Note that there are some explanatory texts on larger screens.

plurals
  1. POUI Thread locking when loading data in background thread
    text
    copied!<p>I have an issue with loading data into a COM object in a background thread. </p> <p>I have some files that are taking a long time to load and when this happens my application locks up and becomes unusable. Because of this I am trying to load the data in a background thread, <code>BackgroundWorker</code> object.</p> <p>I traced into my code and placed a generic <code>Thread.Sleep()</code> in code behind for my Usercontrol that is loading the file. I am able use the application during the <code>Sleep()</code> call but when I replace the <code>Sleep()</code> call with my <code>LoadFile()</code> call it locks the UI thread.</p> <p>Here is the simplified version of the code that I am calling:</p> <pre><code>private void CurrentDocumentChangedEvents() { //fire event for native file viewer var worker = new BackgroundWorker(); worker.DoWork += worker_DoWork; worker.RunWorkerAsync(); gridView1.Focus(); } void worker_DoWork(object sender, DoWorkEventArgs e) { //Call to UserControl to load the file selected. LoadFileForViewing(filePath); } public void showFile(string filePath) { //Method inside UserControl that loads my selected file Thread.Sleep(10000); //axoixctrl_Viewer.ViewFile(false, filePath); } </code></pre> <p>axoixctrl_Viewer is the COM object that is loaded into my Usercontrol. The usercontrol lives in the UI thread, it is initialized when the Form Loads. Is the problem related to creating the COM object on the UI thread or is my threading wrong?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload