Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll have to make sure that the update happens on the correct thread; the UI thread.</p> <p>In order to do this, you'll have to Invoke the event-handler instead of calling it directly.</p> <p>You can do this by raising your event like this:</p> <p>(The code is typed here out of my head, so I haven't checked for correct syntax, etc., but it should get you going.)</p> <pre><code>if( MyEvent != null ) { Delegate[] eventHandlers = MyEvent.GetInvocationList(); foreach( Delegate d in eventHandlers ) { // Check whether the target of the delegate implements // ISynchronizeInvoke (Winforms controls do), and see // if a context-switch is required. ISynchronizeInvoke target = d.Target as ISynchronizeInvoke; if( target != null &amp;&amp; target.InvokeRequired ) { target.Invoke (d, ... ); } else { d.DynamicInvoke ( ... ); } } } </code></pre> <p>Note that the code above will not work on WPF projects, since WPF controls do not implement the <code>ISynchronizeInvoke</code> interface.</p> <p>In order to make sure that the code above works with Windows Forms and WPF, and all other platforms, you can have a look at the <code>AsyncOperation</code>, <code>AsyncOperationManager</code> and <code>SynchronizationContext</code> classes.</p> <p>In order to easily raise events this way, I've created an extension method, which allows me to simplify raising an event by just calling:</p> <pre><code>MyEvent.Raise(this, EventArgs.Empty); </code></pre> <p>Of course, you can also make use of the BackGroundWorker class, which will abstract this matter for you.</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. 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