S
stork
Because the results to BeginInvoke occur async'ly, it stands to reason
that each call of execute is actually a record on a queue, and
therefor, each asyncResult must actually be a separate item on that
queue. Conceptually, the nicest place to put the IAsyncResult to use
for EndInvoke is with the queued item itself, that is, in the execute
method that BeginInvoke enqueued. BeginInvoke fires as needed, and the
"invoked" method cleans itself up by calling the matching EndInvoke.
But, there's no way to actually make this work as above. BeginInvoke
can hit execute before any possible asyncResult assignment takes place.
Consider this pseudocode example:
class MyForm{ }
class MyWorkerThread
{
MyForm form;
IAsyncResult asyncResult;
void execute()
{
form.EndInvoke( asyncResult );
}
void start(int 42)
{
asyncResult = form.BeginInvoke( new executeDelegate( execute ) );
}
}
In the above, asyncResult will be null or invalid inside of execute()
because the assignment to asyncResult will not be completed yet until
the execute() is reached. Short of locking, is there another way to
call form.BeginInvoke so that the asyncResult is passed with it?
Thanks!
that each call of execute is actually a record on a queue, and
therefor, each asyncResult must actually be a separate item on that
queue. Conceptually, the nicest place to put the IAsyncResult to use
for EndInvoke is with the queued item itself, that is, in the execute
method that BeginInvoke enqueued. BeginInvoke fires as needed, and the
"invoked" method cleans itself up by calling the matching EndInvoke.
But, there's no way to actually make this work as above. BeginInvoke
can hit execute before any possible asyncResult assignment takes place.
Consider this pseudocode example:
class MyForm{ }
class MyWorkerThread
{
MyForm form;
IAsyncResult asyncResult;
void execute()
{
form.EndInvoke( asyncResult );
}
void start(int 42)
{
asyncResult = form.BeginInvoke( new executeDelegate( execute ) );
}
}
In the above, asyncResult will be null or invalid inside of execute()
because the assignment to asyncResult will not be completed yet until
the execute() is reached. Short of locking, is there another way to
call form.BeginInvoke so that the asyncResult is passed with it?
Thanks!