Re: Monitoring Threads

Patrick Steele <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <02c801c771fe$c87d8690$6701a8c0@raptor>
SWF.Timer can be used all by itself -- it has no reliance on a control.
Start up a new Windows Forms app and then paste this code in:

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Timer tmr = new Timer();
            tmr.Interval = 1000;
            tmr.Tick += new EventHandler(tmr_Tick);
            tmr.Enabled = true;
        }

        void tmr_Tick(object sender, EventArgs e)
        {
            this.Text = DateTime.Now.ToLongTimeString();
        }

As for multiple UI threads -- I have heard of this but didn't realize
.NET supported it (fully).  I would think encountering multiple UI
threads would be very rare.

--
Patrick Steele
http://weblogs.asp.net/psteele



-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps
and controls [mailto:[email protected]] On Behalf Of
Fabian Schmied
Sent: Thursday, March 29, 2007 8:08 AM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Monitoring Threads


> If you're sure you'll have a message pump running, then using the
> System.Windows.Forms timer will ensure the Elapsed event (if that's
> what event is fired for that timer -- can't recall) fires on the UI
> thread.

Yes, but this only works if the System.Windows.Forms.Timer is _added_ to
a control. SWF.Timer cannot be used without control (or similar
component contrainer), can it?

> And you could always check the Application.MessageLoop property before

> doing anything and throw some kind of exception to let consumers of
> your component know that they must call your component from a UI
> thread.

That's true, but keep in mind there might be more than one UI thread.

Fabian
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.