Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to have the UI Thread invoke the frmMain.refreshStats method. There is of-course many ways of doing this using the Control.InvokeRequired property, and Control.Invoke (<a href="http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx" rel="nofollow noreferrer">MSDN Documentation</a>).</p> <p>You can either have the "EndAsync" method make the method call UI thread safe, or have the refreshStats method check for thread safety (using Control.InvokeRequired).</p> <p>EndAsync UI thread-safe would be something like this:</p> <pre><code>Public Delegate Sub Method(Of T1, T2)(ByVal arg1 As T1, ByVal arg2 As T2) Sub skDataReceived(ByVal result As IAsyncResult) Dim frmMain As Form = CType(My.Application.OpenForms.Item("frmMain"), frmMain) Dim d As Method(Of Object, Object) 'create a generic delegate pointing to the refreshStats method d = New Method(Of Object, Object)(AddressOf frmMain.refreshStats) 'invoke the delegate under the UI thread frmMain.Invoke(d, New Object() {d1, d2}) End Sub </code></pre> <p>Or you can have the refreshStats method check to see if it needs to invoke itself under the UI thread:</p> <pre><code>Public Delegate Sub Method(Of T1, T2)(ByVal arg1 As T1, ByVal arg2 As T2) Sub refreshStats(ByVal d1 As Object, ByVal d2 As Object) 'check to see if current thread is the UI thread If (Me.InvokeRequired = True) Then Dim d As Method(Of Object, Object) 'create a delegate pointing to itself d = New Method(Of Object, Object)(AddressOf Me.refreshStats) 'then invoke itself under the UI thread Me.Invoke(d, New Object() {d1, d2}) Else 'actual code that requires UI thread safety goes here End If End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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