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 / New Users / November 2006

Tip: Looking for answers? Try searching our database.

Pump Messages During Long Operations

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Ingram - 29 Nov 2006 16:04 GMT
"The CLR has been unable to transition from COM context 0x1b0f58 to COM
context 0x1b10c8 for 60 seconds. The thread that owns the destination
context/apartment is most likely either doing a non pumping wait or
processing a very long running operation without pumping Windows
messages. This situation generally has a negative performance impact and
may even lead to the application becoming non responsive or memory usage
accumulating continually over time. To avoid this problem, all single
threaded apartment (STA) threads should use pumping wait primitives
(such as CoWaitForMultipleHandles) and routinely pump messages during
long running operations."

So, in my C# loop (reading in a bunch of images) - how do I pump windows
messages so that my application responds?
David Browne - 29 Nov 2006 16:21 GMT
> "The CLR has been unable to transition from COM context 0x1b0f58 to COM
> context 0x1b10c8 for 60 seconds. The thread that owns the destination
[quoted text clipped - 9 lines]
> So, in my C# loop (reading in a bunch of images) - how do I pump windows
> messages so that my application responds?

You don't.  Instead, avoid calling STA COM components from non-STA threads.

David
Carl Daniel [VC++ MVP] - 29 Nov 2006 16:24 GMT
> "The CLR has been unable to transition from COM context 0x1b0f58 to
> COM context 0x1b10c8 for 60 seconds. The thread that owns the
[quoted text clipped - 9 lines]
> So, in my C# loop (reading in a bunch of images) - how do I pump
> windows messages so that my application responds?

The crude way (that lots of people will probably jump on and say "don't do
that") is to call Application.DoEvents every now and then while you're
reading files (e.g. once per file).

The right way is to move your lengthy processing to a worker thread.  Use
async delegates, the thread pool, the new BackgroundWorker (2.0) class, or
the System.Threading API directly.  Be aware that once you move processing
to a worker thread, you need to marshall all UI access into the correct
thread using Control.{Begin}Invoke.  It's not allowed under Winforms 2.0 for
a thread other than the owning thread to touch any GUI compoent.  (It was
allowed in 1.1 and before, but there was no guarantee that it would work,
and it's prone to deadlocks.  This is a core Windows limitation, not
anything specific to Winforms).

-cd
Mark Ingram - 29 Nov 2006 16:54 GMT
> The crude way (that lots of people will probably jump on and say "don't do
> that") is to call Application.DoEvents every now and then while you're
[quoted text clipped - 11 lines]
>
> -cd

Ahh, DoEvents, that was the hack I was looking for. A thread is
preferable long term, but for now I just want to get rid of the error :)

Thanks,

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.