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 / CLR / September 2003

Tip: Looking for answers? Try searching our database.

invoke on UI thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 09 Sep 2003 15:43 GMT
I understand the notion that a UI thread should be
responsible for managing the UI elements; therefore,
worker threads need to call invoke.  I don't understand
the technical reason for this.   What is it about the
Win32 message loop that doesn't like worker threads to
update the UI and why does it work anyway (at least most
of the time)?

Thanks for shedding some light,
Paul
Thomas Tomicek [MVP] - 09 Sep 2003 16:09 GMT
Read up the erquirements for ActiveX Controls and the meaning of Single
Threaded Appartment (in the COM documentation, not in the .NET
documentation).

The reason is indeed in the Win32 message loop and legacy.

It works often because not all controls are native- if basically blows the
moment you touch a critical component that is managed by the OS and actually
does use the environment it has a right to be there.

The documentation on whow COM works and what ActiveX controls are is pretty
enlighting for this.

Signature

Regards

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

> I understand the notion that a UI thread should be
> responsible for managing the UI elements; therefore,
[quoted text clipped - 6 lines]
> Thanks for shedding some light,
> Paul
Michael Bray - 10 Sep 2003 23:28 GMT
On a similar subject, I've had problems with Invoke() locking up -
I've verified (with Console.WriteLine's) that the function that I'm
requestion with Invoke never executes...  so I've resorted to NOT
using Invoke, even though I know I should.  Any ideas?
Thomas Tomicek [MVP] - 11 Sep 2003 07:39 GMT
> On a similar subject, I've had problems with Invoke() locking up -
> I've verified (with Console.WriteLine's) that the function that I'm
> requestion with Invoke never executes...  so I've resorted to NOT
> using Invoke, even though I know I should.  Any ideas?

Change the (bad) decision to not use invoke where you should.
Paul - 11 Sep 2003 14:34 GMT
In COM, when calling an object in STA from another
apartment, COM will marshall the call across apartments.  
Tom, are you saying that .NET uses COM underneath to
marshall calls from free-threaded apartment to STA where
the UI elements reside?  Essentially, calling Invoke(),
makes sure that the correct thread manages the UI element
even though a worker thread also has the UI element's
handle?

>-----Original Message-----
>> On a similar subject, I've had problems with Invoke() locking up -
[quoted text clipped - 5 lines]
>
>.
Thomas Tomicek [MVP] - 11 Sep 2003 14:45 GMT
> In COM, when calling an object in STA from another
> apartment, COM will marshall the call across apartments.
[quoted text clipped - 4 lines]
> even though a worker thread also has the UI element's
> handle?

Naturally there sis a COM threading model below. How else could it accept
ActiveX controls on a form without problems?

The documentation is clear: you are supposed to invoke and thus marshal back
to the UI thread.

This, though, has nothing to do with COM, btw-  the threading model was IMHO
there before COM came around.

Signature

Regards

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


Rate this thread:







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.