By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,996 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,996 IT Pros & Developers. It's quick & easy.

BeginInvoke and Callback

P: n/a
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
May 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 10 May 2006 17:53:55 -0400, Joe wrote:
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
May 10 '06 #2

P: n/a
Joe
Thanks. That was the problem. I had a feeling but wasn't sure...

"Mehdi" <vi****@REMOVEME.gmail.com> wrote in message
news:1u******************************@40tude.net.. .
On Wed, 10 May 2006 17:53:55 -0400, Joe wrote:
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

May 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.