Date Time question

  • Thread starter Thread starter Zach
  • Start date Start date
Z

Zach

I would like to express the time with
the time continually changing. I can get
it to show once, but then it stays that way,
using a loop jams. Is there a way to do this?
 
If this is a web application, you would need to do it client side (ie
javascript).

If this is a windows application, one way would be to add a timer to the
winform with a period of (say) a second (or minute..) and "refresh" the time
when the timer event fires.

Scott
 
No it isn't a web application

if I code

while(true)
{
// show the time in a textBox
}

The app blocks.
What can I do to stop it from blocking?

Zach
 
Hi Zach,
as Scott pointed out you will need to use something like a Timer. If you
go to the toolbox in design view you will see a Timer Components, drag it
onto your form, you can now set its interval property to 1 second (I believe
it is based on milliseconds so you will have to set it to 1000) then you
need to add an event handler to handle the Tick event which will fire every
1000ms. In this event you can update the label you have on the form with the
current time.

Hope that helps
Mark R Dawson
http://www.markdawson.org
 
I drag a timer onto the form.
I click the timer twice
It creates a timer_Tick(...)
In the timer_Tick method I put logic to display the time in a label
Nothing happens

Zach
 
Hi Zach,
call refresh method for that label

something like labelname.Refresh();

Regards,
Dhans
 
Zach said:
I drag a timer onto the form.
I click the timer twice
It creates a timer_Tick(...)
In the timer_Tick method I put logic to display the time in a label
Nothing happens

Zach

I think you need to "Enable" the timer, somewhere in the initialisation of your form.

Hans Kesting
 
What I want to do is to show a changing time
in a label. If I show the time once in the label
that works ok, if I do it repeatedly, like in
a loop, with a second interval, the app blocks.

Zach.
 
I would question the utility of this compared to the overhead of having
another thread/timer going in your app. I mean people already have various
ways to see the current local time on their machine. Is this something you
must have in the form for some reason. If so, the Form based Windows Timer
control is the easiest way to do this.
 
The problem lies in the fact that .Net Windows Forms are really Win32 forms.
They are not truly multi-threaded, and using them in a multi-threaded .Net
app can be tricky.

Here are some very helpful articles on threading and events in Windows
forms:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms08162002.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms08162002.asp

The .Net 2.0 platform has some really nice enhancements to help with these
issues.
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.
 
Back
Top