Note that there are some explanatory texts on larger screens.

plurals
  1. PODelegate, BeginInvoke. EndInvoke - How to clean up multiple Async threat calls to the same delegate?
    primarykey
    data
    text
    <p>I've created a Delegate that I intend to call Async. </p> <h2>Module Level</h2> <pre><code>Delegate Sub GetPartListDataFromServer(ByVal dvOriginal As DataView, ByVal ProgramID As Integer) Dim dlgGetPartList As GetPartListDataFromServer </code></pre> <h2>The following code I use in a method</h2> <pre><code> Dim dlgGetPartList As New GetPartListDataFromServer(AddressOf AsyncThreadMethod_GetPartListDataFromServer) dlgGetPartList.BeginInvoke(ucboPart.DataSource, ucboProgram.Value, AddressOf AsyncCallback_GetPartListDataFromServer, Nothing) </code></pre> <p>The method runs and does what it needs to</p> <h2>The Asyn callback is fired upon completion where I do an EndInvoke</h2> <pre><code>Sub AsyncCallback_GetPartListDataFromServer(ByVal ar As IAsyncResult) dlgGetPartList.EndInvoke(Nothing) End Sub </code></pre> <p>It works as long as the method that starts the BeginInvoke on the delegate only ever runs while there is not a BeginInvoke/Thread operation already running. Problem is that the a new thread could be invoked while another thread on the delegate is still running and hasnt yet been EndInvoke'd. </p> <p>The program needs to be able to have the delegate run in more than one instance at a time if necessary and they all need to complete and have EndInvoke called. Once I start another BeginInvoke I lose the reference to the first BeginInvoke so I am unable to clean up the new thread with an EndInvoke. </p> <p>What is a clean solution and best practice to overcome this problem?</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.
 

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