Re: Will Async Callback hander code ever be called if server offli

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Ken Kolda (ken.kolda_at_elliemae-nospamplease.com)
Date: 08/09/04


Date: Mon, 9 Aug 2004 07:56:37 -0700

The docs are correct -- the call to EndInvoke within your callback handler
will raise an exception if the server is offline. But that doesn't mean your
callback won't be called. When you call BeginInvoke, the delegate is taked
to the thread pool. When one of the threads picks it up, it attempts to call
the designated method. If the server is offline, the method should throw an
exception. The exception is caught in the executing thread and saved off. It
then invokes your callback handler, if any.

When you call EndInvoke, the originally caught exception is rethrown so you
can determine what you want to do with it.

Regardless, the easiest way to see this is to try it. I wrote some quick
code to test this out and it seemed to work as I would have expected -- the
callback gets called and, when I call EndInvoke, I get the remoting
exception caused by the disconnected server.

Ken

"Dave Boal" <DaveBoal@discussions.microsoft.com> wrote in message
news:6E53B680-2AEC-4FB3-A31E-5A4F66464EC7@microsoft.com...
> Thank you for your response. I am confused on this matter, because I docs
> say that calling .EndInvoke on the delegate either blocks your code until
you
> get a response, or raises an exception if the server is unavailable.
>
> I do not see a way for this callback code to ever be called if the server
is
> offline, and thus the contained .EndInvoke method is never be called, and
you
> get no notification that it will not be called.
>
>
> "Ken Kolda" wrote:
>
> > The async handler will be called, but when you call EndInvoke it will
raise
> > an exception indicating that the server has been disconnected. So, make
sure
> > to wrap your call to EndInvoke in a try/catch.
> >
> > Ken
> >
> >
> > "Dave Boal" <DaveBoal@discussions.microsoft.com> wrote in message
> > news:48C02C4D-C8CC-40A7-AE9D-A98639E938C2@microsoft.com...
> > > In the sample code that follows, "LongProcessCallbackHandler" is the
name
> > of the Async Callback hander code. Will it ever be called, if the
server is
> > offline?
> > >
> > > Sample Client Code calling a Remote with callback:
> > >
> > > ...class async call method:
> > > public void CallRemoteAsyncly(){
> > > remoteDelegate del = new remoteDelegate(remote.LongProcess);
> > > AsyncCallback delCB = new AsyncCallback(LongProcessCallbackHandler);
> > > del.BeginInvoke("param", delCB , null);
> > > }
> > >
> > > private LongProcessCallbackHandler(IAsyncResult asyncResult) {
> > > callBackResult = del.EndInvoke(asyncResult);
> > > }
> > >
> >
> >
> >



Relevant Pages

  • Re: Close TCP/IP Listening Socket
    ... I just caught the exception as part of shutdown but... ... code in the IAsyncResult passed into the callback. ... > I connect to the server when I stop the server to unblock the listener ... > thread so it will fall out of the connection processing loop. ...
    (microsoft.public.dotnet.framework)
  • RE: Backup & Monitoring not working!
    ... Error message in Windows Small Business Server 2003: ... Microsoft CSS Online Newsgroup Support ... This newsgroup only focuses on SBS technical issues. ... An unhandled exception occurred during the execution of the ...
    (microsoft.public.windows.server.sbs)
  • Re: Sharepoint 2007 - Installation Error - Failed to register SP s
    ... Windows 2000 Server. ... It is a bug with Beta 2 where the database server is running Windows 2000. ... Server I have the following exception: ... RunBehavior runBehavior, String resetOptionsString) ...
    (microsoft.public.sharepoint.portalserver)
  • return from server only works for built-in types
    ... But when I call _r.GetStatisticsthe client fails with the exception shown ... GetStatistics fails when client and server is on different networks. ... Win32 Version: 2.0.50727.832 ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Sharepoint 2007 - Installation Error - Failed to register SP servi
    ... The issue stems from the installer going to a remote computer for SQL Server. ... Server I have the following exception: ... exception, Boolean breakConnection) ... RunBehavior runBehavior, String resetOptionsString) ...
    (microsoft.public.sharepoint.portalserver)