Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx" rel="nofollow">BackgroundWorker</a>-class. It's usage is very simple and it is used quite often for tasks such as loading data. The following example shows you it's usage:</p> <pre><code>BackgroundWorker bgWorker = new BackgroundWorker() { WorkerReportsProgress=true}; bgWorker.DoWork += (s, e) =&gt; { // Load here your data // Use bgWorker.ReportProgress(); to report the current progress }; bgWorker.ProgressChanged+=(s,e)=&gt;{ // Here you will be informed about progress and here it is save to change/show progress. // You can access from here savely a ProgressBars or another control. }; bgWorker.RunWorkerCompleted += (s, e) =&gt; { // Here you will be informed if the job is done. // Use this event to unlock your gui }; bgWorker.RunWorkerAsync(); </code></pre> <p>The use of the BackgroundWorker allows the UI-thread to continue it's processing and therefore the application rests responsive during loading. But because of this, you have also to ensure that no actions can take place that rely on the loaded data. A very simple solution is to set your main UI elements IsEnabled-property to false and in RunWorkerCompleted you set it to true. With a little fantasy you can improve this dumb behaviour tp a nice UI-experience (depending on the App).</p> <p>It is general a good a advice to do long time operations in a separate thread (BackgroundWorker). One caveat is there: Do not create WPF-Elements in the DoWork-event. This will not do because all derived types of DependencyObject must be created in the same thread they are used.</p> <p>There are other solutions to do this, for example creating directly a thread or with the event based async pattern, but I recommend to use BackgroundWorker for your task because it handels for you the plumbing. In the end, the result is the same but the way to it is much easier.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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