Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Link Timer to a new thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RP - 29 Aug 2007 19:53 GMT
I have a Timer control on a form. When this Timer starts, it will do
certain task on every tick. I want that this Timer be linked to a new
thread so that the Timer does not disturb other activities. How to
create a new thread and link this Timer to it?
Ignacio Machin ( .NET/ C# MVP ) - 29 Aug 2007 20:17 GMT
Hi,

>I have a Timer control on a form. When this Timer starts, it will do
> certain task on every tick. I want that this Timer be linked to a new
> thread so that the Timer does not disturb other activities. How to
> create a new thread and link this Timer to it?

You do not need to "link" the timer to the thread (or threads to be more
precise).
Just create a new thread in the Tick event.
In case ou need to have access to the UI from these threads use
Control.Invoke
Peter Duniho - 29 Aug 2007 20:43 GMT
> I have a Timer control on a form. When this Timer starts, it will do
> certain task on every tick. I want that this Timer be linked to a new
> thread so that the Timer does not disturb other activities. How to
> create a new thread and link this Timer to it?

In addition to what Ignacio already wrote...

It seems to me that if you necessarily want the timer-signaled code to
execute on a different thread, then one of the Timer classes that
actually use a different thread for signaling the timer would be a
better solution than using the Forms.Timer class.

Forms.Timer is great for situations when you specifically want the
timer-signaled code executing on the main UI thread and the resolution
is sufficient for your needs.  But it sounds like you want the opposite
(not executing on the main UI thread) and so using Forms.Timer is
counter-productive.

Also, if you still wind up for whatever reason assigning a different
thread to the code in response to the signaling of the timer, it would
probably be better to use a thread pool thread rather than creating a
whole new one.  This is a general rule, not absolute advice.  As the
timer interval is longer, and the code executed takes more time, the
overhead of creating a brand new thread is made relatively smaller and
isn't as big a problem.

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.