Re: Managed Asynchronous Pluggable Protocol and Threads

From: Igor Tandetnik (itandetnik_at_mvps.org)
Date: 02/03/05


Date: Wed, 2 Feb 2005 20:02:05 -0500


"Max K." <maxk@eden.rutgers.edu> wrote in message
news:1107390883.318555.282940@g14g2000cwa.googlegroups.com
> Here are my observations. Originally my APP is created on a thread in
> STA apartment (debugger shows
> Thread.CurrentThread.AppartmentState=STA). When ReportProgress is
> called Thread.CurrentThread.AppartmentState is changed to MTA.

I suspect CLR got confused. In my experience, HTTP APP calls you back on
a worker thread that did not initialize COM at all.

URLMon blatantly disregards COM threading rules. It only works because
direct interface pointers are used throughout, no marshalling is
involved, so COM runtime is out of the picture and does not have a
chance to complain. The whole thing is held together with bubble gum and
duct tape, I had to tread very carefully to avoid breaking it.

I shudder to think about how .NET runtime would behave when thrown into
this mess. I have my doubts about the feasibility of a managed APP
handler.

> I suspected that system has a problem calling my Continue after I
> called target Switch and tried just for troubleshooting to call
> Continue myself from my Switch method.

But that defeats the whole point. Switch / Continue pair is there for a
reason - it allows the APP to request the host application to call it
back on the main STA thread, mostly when it needs to do honest COM stuff
that would break from the worker. Essentially, when you call Switch from
the worker, MSTHML posts a message to the hidden window it maintains on
the main thread. When the message arrives, it calls Continue on you,
thus effectively switching to the main thread.

-- 
With best wishes,
    Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925 


Relevant Pages

  • Re: Hiding VIO window screensize changes?
    ... But this isn't about diving into Dive, and the original app (over ... Prefix "1": type MyApp.EXE in a fullscreen CMD.EXE session ... use a regular WPS file object representing MyApp.EXE (VIO) ... to be a minimized switch to 40x25, ...
    (comp.os.os2.programmer.misc)
  • Re: [opensuse] KDE4.x.x Activities
    ... the leaving that app open switch back to your other activity via the ... Maybe the KDE team need a bit of a pokingto jiffy them up a little on ... SuSE Linux 10.3-Alpha3. ...
    (SuSE)
  • Re: Forms Creation Question
    ... Set Form2 as active form ... However, you better watch out when you switch between forms, ... MVP - Windows CE.NET, MCSD.NET, .NETcf consultant ... >> I show tons of instances of my app opened, only because a bunch of forms ...
    (microsoft.public.dotnet.framework.compactframework)
  • Update - How to prevent Hard Flicker present in Access database
    ... Switch back to the app, after I judge that the app has finished loading. ... AND it prompted a VISIBLE error. ... "Marshall Barton" wrote: ...
    (microsoft.public.access.modulesdaovba)
  • Re: How can I set focus to one of the running processes in the task list?
    ... I've got a list of running processes using opennetcf - how do I switch ... make sure the app uses CreateMutex and FindWindow to ... CreateMutex with the same mutex name to check whether the app is ...
    (microsoft.public.pocketpc.developer)

Loading