Why is Format Slow the first time?

  • Thread starter Thread starter Bob Graham
  • Start date Start date
B

Bob Graham

This code:
txRate.Text = Format(payRate, "C")

(payRate is already succesfully set to a value such as 15D)

takes about 3-4 seconds to run the first time, after that it's plenty fast.

What makes it slow on the first call?

Bob Graham
 
I've tried changing it to the more .net correct syntax:
txRate.Text = payRate .ToString("C")

But it still runs just as slow.

Funny thing is, I have identical code in another form that runs fast first
time, and that form was derived from this one.

Bob Graham
 
Does it run slow when not attached to the debugger (Debug > Start Without
Debugging) or when compiled into release mode?

I have this problem with the first exception thrown in an application when
attached to the debugger - the first exception takes about 5-10 seconds or
so to be caught, but any exceptions thrown after that run ok. This still
happens even if the exception is raised and caught somewhere in the
framework. If an internal exception is being raised in the Format function,
this could be the cause. Goto the Debug > Exceptions window and set all
exceptions to be caught by the debugger and you'll see if an exception is
being raised.

Even if one is being raised, there isn't anything you can do about it. Rest
easy in the fact that it should run ok in Release mode ;)

HTH,

Trev.
 
Trev,

Thanks for your reply, I never did find the reason for that problem; I
deleted the textbox and created another one with a different name, changed
the code refs and everything is fine. There were no errors being generated.
It seems like the control was 'poisoned' as it were, by some obscure setting
or the like. I should probably learn to read the .resx files or something.

Bob
 
Back
Top