DateTime.Now not working?

  • Thread starter Thread starter Bryce K. Nielsen
  • Start date Start date
B

Bryce K. Nielsen

I have a Form that has a method that sets a label's text to
DateTime.Now.ToString(). Strange thing is, when I call the form twice from
the same app, the label shows the old DateTime value. It's almost as though
either the Form didn't get recreated, or if the DateTime didn't reflect the
current date. With my form, I have it in a using clause though, so it should
be freed, right? Another problem, this only happens at runtime, when I step
through in the debugger, works fine.

Anyone else experience odd behavior with DateTime.Now?

-BKN
 
Can you put up a simple example based upon your code?
Unfortunately no, since like I've said it doesn't happen with the debugger.
In fact, it doesn't happen on my development machine, it only seems to
happen on one of the Win2003 R1 servers. Wasn't sure if anyone else was
experiencing problems with DateTime.Now...

-BKN
 
Bryce,
As Greg indicated, you can be quite sure that there is nothing wrong with
"DateTime.Now".
What's more likely is the way you (as you say) are "calling the form".
if you create an instance of a form and that causes your method to run, and
then you re-use the same instance (perhaps making calls to Show or Hide),
your method won't run a second time.

There are event handlers in the Form Class you can put the call to the
method into that will ensure it is called again.
Peter
 
What's more likely is the way you (as you say) are "calling the form".
if you create an instance of a form and that causes your method to run,
and
then you re-use the same instance (perhaps making calls to Show or Hide),
your method won't run a second time.

There are event handlers in the Form Class you can put the call to the
method into that will ensure it is called again.

Positive it's not that, I am "using" the form so it should be destroyed. The
only thing I think might be happening is that it's getting fished out of GC?

Here's basically what I'm doing:

using(MyForm form = new MyForm())
{
form.PrepForm();
form.ShowDialog();
}

in the PrepForm() is where the label is getting DateTime.Now.ToString(). I'm
completely at a loss myself since it seems like this should never happen :/

-BKN
 
If thats all thats happenning it should be a trivial matter to get it to
happen in a test app ?

Can you post your code for PrepForm?

btw: you can't undispose a form.

Cheers,

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top