BeginInvoke and Callback

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

In the callback I need to call an event letting the calling form know that
the operation completed. If the operation fails, the main form needs to show
another form. The problem I get is when the Callback returns it hangs the
app.

Here's the callback:
private void Callback(IAsyncResult ar)
{
System.Runtime.Remoting.Messaging.AsyncResult result =
(System.Runtime.Remoting.Messaging.AsyncResult)ar;

RequestHandler handler = result.AsyncDelegate as RequestHandler;

if (handler != null)
handler.EndInvoke(ar);

if (RequestComplete != null)
RequestComplete(this);

}

Any ideas?

-Joe
 
In the callback I need to call an event letting the calling form know that
the operation completed. If the operation fails, the main form needs to show
another form. The problem I get is when the Callback returns it hangs the
app.

A callback function is always executed in a worker thread (usually taken
from the thread pool). Any UI control *must* be accessed only from the UI
thread. You should therefore use Conttol.Invoke or Control.BeginInvoke to
marshall the call to the UI thread before accessing your form or any UI
control from your callback method
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top