[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Will Async Callback hander code ever be called if server offline?

Dave Boal

8/3/2004 11:15:00 PM

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);
}

4 Answers

Sunny

8/4/2004 3:04:00 PM

0

Hi,

In article <48C02C4D-C8CC-40A7-AE9D-A98639E938C2@microsoft.com>,
DaveBoal@discussions.microsoft.com says...
> 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);
> }
>
>

No, it will not.

Sunny

Ken Kolda

8/4/2004 3:30:00 PM

0

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);
> }
>


Dave Boal

8/6/2004 5:25:00 AM

0

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);
> > }
> >
>
>
>

Ken Kolda

8/9/2004 2:57:00 PM

0

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);
> > > }
> > >
> >
> >
> >