There is no cleaner or different way for one simple reason:

Compatibility with ActiveX components.

They require STA and they limit the whole thing to this type of message
pump.

Now, dropping them is not an option, too. A lot depends on this model.

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
(CTO PowerNodes Ltd.) 

> -----Original Message-----
> From: Moderated discussion of advanced .NET topics. 
> [mailto:[EMAIL PROTECTED] On Behalf Of Jade Burton
> Sent: Montag, 23. Februar 2004 03:12
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] Thread with message pump (UI thread)
> 
> As a sidebar to the topic of threads and message pumps, am I 
> the *only* person in the world who wishes there was greater 
> *cohesion* and
> *transparency* between WinForms' and worker threads?
> 
> Why, in 2004, do programmers have to call some hokey 
> form.Invoke(SetSomeControlMethod, blah) in order to update 
> something on the form from within a worker thread?
> 
> When I first saw .NET I had hoped that a cleaner model had 
> been adopted by WinForms, but alas I was disappointed to see 
> it's but another Windows wrapper.
> 
> I'm not sure there's a clean alternative to having a message 
> pump drive the UI (maybe there is?), but there *must* be a 
> cleaner way than the current segregated STA-MTA ideology 
> which has weasled its way into .NET?  For example, why can't 
> I just call form.SetSomeControlMethod and have it update 
> inline, without any windows messages being sent?  (And why 
> can't I create a modal dialog from within a worker that 
> simply blocks until the user clicks OK, rather than using 
> another message loop etc?)
> 
> Or are we stuck with what I would regard as a system that 
> requires the programmer to write (and - ugh - think about) 
> "non-business logic" plumbing code...
> 
> Jade Burton
> 
> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] Behalf Of 
> Shawn A. Van Ness
> Sent: Saturday, 21 February 2004 10:48 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] Thread with message pump (UI thread)
> 
> 
> Call Application.Run (or even Application.DoEvents) do 
> establish a message queue for your secondary thread.
> 
> A better answer: You should not be performing any 
> long-blocking operations on your main UI thread.  This rule 
> goes right up there alongside "thread that creates the window 
> services the window".
> 
> (By "it is difficult to free the main thread" I assume you 
> mean your main UI thread is performing some long-blocking 
> operation -- like socket i/o, or calculating pi to 3000 
> decimal places, or what have you.  Don't do that.)
> 
> -Shawn
> http://www.windojitsu.com/
> 
> On Fri, 20 Feb 2004 13:35:57 -0500, Aman Jain 
> <[EMAIL PROTECTED]> wrote:
> 
> >Hi Everybody,
> >
> >The alarm manager in my Windows Forms application has a 
> alarm control 
> >(User control) that is used to display errors.
> >This is created on the Main thread. Whenever any calls are 
> made on this 
> >control to display errors, we take care to switch to the Main thread 
> >(windows principle: thread that creates the window services 
> the window) 
> >using
> >
> >
> >            private void OnAlarmMessageReceived(AlarmMessage msg)
> >            {
> >                  if(InvokeRequired) // Pass on to GUI thread
> >                  {
> >                        BeginInvoke(new 
> >AlarmMsgReceivedHandler(OnAlarmMessageReceived), new 
> Object[] { msg } );
> >                        return;
> >                  }
> >                  // whatever needs to be done
> >            }
> >
> >This works fine but with the requirement that the main 
> thread is free.
> >Now, there are many situations where it is difficult to free 
> the main 
> >thread but there are errors that need to be displayed.
> >What I need is a UI thread  that remains alive during the 
> application 
> >lifetime on which I can create and service the alarm window. In the 
> >managed world (using C#) , how do we create a thread with a message 
> >pump as opposed to a worker thread  ?
> >
> >Any help is greatly appreciated.
> >
> >Thanks in advance,
> >Aman
> >
> >
> >===================================
> >This list is hosted by DevelopMentor(r)  
> http://www.develop.com Some .NET 
> >courses you may be interested in:
> >
> >NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles 
> >http://www.develop.com/courses/gaspdotnetls
> >
> >View archives and manage your subscription(s) at 
> >http://discuss.develop.com
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com 
> Some .NET courses you may be interested in:
> 
> NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles 
> http://www.develop.com/courses/gaspdotnetls
> 
> View archives and manage your subscription(s) at 
> http://discuss.develop.com
> 
> --
> This message has been scanned for viruses and dangerous 
> content by MailScanner, and is believed to be clean.
> 
> 
> --
> This message has been scanned for viruses and dangerous 
> content by MailScanner, and is believed to be clean.
> 
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com 
> Some .NET courses you may be interested in:
> 
> NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles 
> http://www.develop.com/courses/gaspdotnetls
> 
> View archives and manage your subscription(s) at 
> http://discuss.develop.com
> 
> 

===================================
This list is hosted by DevelopMentor®  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to