Catching exceptions inside static callback methods

  • Thread starter Thread starter Adam
  • Start date Start date
A

Adam

If I catch an exception in a static callback method like:

private static void ResponseCallback(IAsnycResult
asyncResult)
{
try { //code...code...code }
catch (WebException e)
{ //handle exception }
}

will that that WebException object remain for the life of
the process???

I have a windows service which makes WebRequests and uses
a callback to handle asynchronous requests, but if
there's an exception raised, I want to be able to
continue using this class later on. I've had a hard time
debugging it, but it seems like once there's an exception
raised, I keep catching an exception, even when I'm
pretty sure the request should succeed.

Does the WebException remain in memory the same as other
static members??? If so how, should this kind of
situation be coded?

Thanks
 
Adam, no, that web exception will not always be in memory. It sounds like
there is something else going on with the methods which you think should be
successful. How are you doing your debugging? If you are still seing a
problem please post a complete, runnable sample that demonstrates the
problem.
 
Thanks Greg,

That's what I thought. Debugging is only a problem
because the problem occurs so rarely and I've been too
busy to set up a workable test bed to reproduce the
problem. I'd have to have a web site that returns a 401
access denied error, recompile etc, etc.

Posting a working version might be tricky, since I'd need
to post several classes. It's a service, but if (more
likely when) I get to that point, I'll create a paired
down version of the program. Then if I still can't
figure it out, I'll repost. Thanks again.
 
Back
Top