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 / .NET Framework / Compact Framework / August 2007

Tip: Looking for answers? Try searching our database.

Start a Timer on a Thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Harry Simpson - 24 Aug 2007 21:25 GMT
I've been using CF for quite a while but have not goettn into the threading
portion much at all.  I've found some decent articles regarding it. My boss
asked me if I could "Start a timer on a seperate thread" and I really didn't
know what to tell him - i knew we could execute a method on a thread but
figured we could also control a timer's start event too.  Is there any
reason why this could not be done in CF 2?

TIA
Harry
Christian Resma Helle - 25 Aug 2007 09:05 GMT
Hi Harry,

If you want to access a System.Windows.Forms.Timer from a thread then you
have to use Control.Invoke(). Something like this:

static void ThreadWorker() {
 this.Invoke(new EventHandler(TickerStartMethod));
}

void TimerStartMethod(object sender, EventArgs e) {
 // Do stuff to your Timer...
}

Signature

Regards,
Christian Resma Helle
http://christian-helle.blogspot.com

> I've been using CF for quite a while but have not goettn into the
> threading portion much at all.  I've found some decent articles regarding
[quoted text clipped - 5 lines]
> TIA
> Harry
<ctacke/> - 25 Aug 2007 16:08 GMT
Use the System.Threading.Timer class.  That starts a thread.  A Forms timer
should only be used on the primary thread.

Signature

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com

> I've been using CF for quite a while but have not goettn into the
> threading portion much at all.  I've found some decent articles regarding
[quoted text clipped - 5 lines]
> TIA
> Harry
Simon Hart - 28 Aug 2007 21:12 GMT
Harry,

just to add to what Chris said, the simple rule of thumb which is easy to
remember is; only ever use the System.Windows.Timer class within your UI
code/thread not within worker thread code and use System.Threading.Timer
otherwise.

Signature

Simon Hart
http://simonrhart.blogspot.com

> Use the System.Threading.Timer class.  That starts a thread.  A Forms timer
> should only be used on the primary thread.
[quoted text clipped - 8 lines]
> > TIA
> > Harry

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.