exception pause

  • Thread starter Thread starter allen
  • Start date Start date
A

allen

I'm having a problem in that the first time an exception is thrown in
my app, there is about a 2 second pause. After that first time,
subsequent exceptions go very quickly. This pause is really annoying
the users who think the application is having problems, is there any
way I can make it not happen?

further, the reason this is happening is that I'm trying to test a
class to see if that class implements a certain interface. I'm not
sure how to do that without doing a

IMyInterface imyint = (IMyInterface)someclass;

and doing this will always throw an exception if the class doesn't
implement the exception.
 
allen said:
I'm having a problem in that the first time an exception is thrown in
my app, there is about a 2 second pause. After that first time,
subsequent exceptions go very quickly. This pause is really annoying
the users who think the application is having problems, is there any
way I can make it not happen?

I've only seen this happen in a debugger. Are your users running your
app in the debugger?

If not, could you post a short but complete program which demonstrates
the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
further, the reason this is happening is that I'm trying to test a
class to see if that class implements a certain interface. I'm not
sure how to do that without doing a

IMyInterface imyint = (IMyInterface)someclass;

and doing this will always throw an exception if the class doesn't
implement the exception.

Use the "is" or "as" operators:

IMyInterface imyint = someclass as IMyInterface;
if (imyint != null)
{
....
}

or

if (someclass is IMyInterface)
{
IMyInterface imyint = (IMyInterface) someclass;
...
}
 
you are absolutely correct on both points. Thanks for pointing that
out, that helped me a great deal.
 
Back
Top