Click to See Complete Forum and Search --> : [RESOLVED] [2.0] real time display of data
ini_hendry
Aug 13th, 2006, 12:06 PM
right now, i need to write a form which need to be updated frequently.
let say it every 3s i update it.
what is the best technique to do this in WinForms ?
Can i do this with the System.Timers.Timer class ?
The timer class is in multithread environment.
When i write some code, i got problem displaying updated data in control label. It says that label is being used by another thread and recommend me to use Console.WriteLine() to display updated data.
Can i use control label instead of Console ? bcoz when other user (without vs2005) run my program, he/she wouldn't be able to see the result in written in console ? am i right here?
sorry, its kind of mess here..>< any solution / idea ?
wossname
Aug 13th, 2006, 01:47 PM
It depends what kind of project you started. Sounds like you started a Console project.
Start a new project but make sure you select "Windows Application" instead of "Console Application".
ini_hendry
Aug 13th, 2006, 02:43 PM
no, i use Windows application form, not console.
jmcilhinney
Aug 13th, 2006, 06:25 PM
What type of Timer are you using? If you use a Windows.Forms.Timer then the Tick events will be raised in the UI thread. The upside of this is that you can access controls directly, but the downside is that if the UI thread is busy the Tick event handler will not be executed until it becomes free. If you're using a Timers.Timer then the Elapsed events can be raised either in the UI thread or a worker thread. If you add the Timer to a form in the designer then its SynchronizingObject property will be set to that form by default, which means that the Elapsed events will be raised in the UI thread, which owns the form's handle. If you create your Timer in code then its SynchronizingObject property will be Nothing by default, so the Elapsed events will be raised in a worker thread. The upside of this is that your event handler will be executed when you expect the event to be raised. The downside is that you have to use a delegate to access controls on the form. Even if you do that, you still have to wait until the UI is not busy before it can execute the method that you want to invoke. You can search for "invokerequired" with my user name for examples of using a delegate to make a cross-thread control access.
ini_hendry
Aug 14th, 2006, 09:20 AM
ouw..
your post resolve all my problems.
i've been using System.Timers.Timer class.
i should use System.Windows.Forms.Timer,i guess that the most appropiate class for my WinForms application.
with System.Windows.Form.Timer, i think wouldn't have cross thread problem anymore..
thx a lot
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.