Re: Threading Issues (If you can answer this, I'll kiss you.)

From: Jerry Camel (rlrcstr_at_msn.com)
Date: 05/19/04


Date: Wed, 19 May 2004 14:48:45 -0400

That helps explain the what's happening. I had worked around it by spawning
a new thread that does nothing but register for the system event. Now I
understand why that works. I'll look into the MTAThread attribute as a
solution as well...

Here's the kiss I promised... >*< SMACK >*<

I promise not to kiss you again if you can answer this...

The session ending event will tell me if the user is logging off or shutting
down, but does not differentiate between a user shutting down and a user
restarting the box? How can I tell what action the user has tried to
initiate? Thanks for you insight.

Jerry

"Stephen Martin" <smartin@removethis.emsoft.andthis.ca> wrote in message
news:%234BuF%23cPEHA.640@TK2MSFTNGP12.phx.gbl...
> When you register for a SystemEvent a window is created to receive the OS
> broadcast messages. In your case the window is created on your main thread
> but that thread is suspended so when the session ending broadcast message
is
> sent it is not read from the message queue and your SessionEnding handler
is
> never called.
>
> On the other hand when you register for the process exit event the system
> simply registers a wait on the process handle with the ThreadPool. When
the
> process exits a threadpool thread then calls your event handler. So the
Exit
> handler is not blocked by suspending your thread since it is called on a
> different thread.
>
> I assume in your case that your app is a console app and you do not want
to
> use a form on your main thread to provide a message pump for the broadcast
> window. If that is the case, I think adding a MTAThread attribute to your
> Main function in wrapper.exe might do the trick. The framework assumes
that
> any STA thread has a UI and so creates the broadcast window on that thread
> but if the thread is MTA then no UI is assumed and a thread is created
> specifically to handle the broadcast messages. The VB compiler, by
default,
> makes your Main thread STA unless you add the MTAThread attribute.
>
>
> "Jerry Camel" <rlrcstr@msn.com> wrote in message
> news:OU%23wjFOPEHA.560@TK2MSFTNGP10.phx.gbl...
> > Any insight here is greatly appreciated... (Eveything is in VB .NET)
> >
> > Here's the baisc app flow:
> > -------------------------------------
> > Launch wrapper.exe:
> > wrapper.exe registers for the SessionEnding system event
> > wrapper.exe stores a pointer to its thread in MainThread
> > wrapper.exe declares, withevents, a process variable: np
> > wrapper.exe does some basic maintenance
> > wrapper.exe populates np with process info and sets
> > fp.EnableRaisingEvents to True
> > wrapper.exe launches fp
> > wrapper.exe suspends its thread <- Waiting for fp exit
> > wrapper.exe does some basic maintenance
> > Exit wrapper.exe
> >
> > SessionEnding Handler: (User is logging off or shutting down without
> > exiting fp)
> > force fp to exit
> > End Handler
> >
> > fp Exit Handler: (fp has exited either via user interaction or the
> > SessionEnding Handler)
> > resume MainThread
> > End Handler
> > ------------------------------------
> >
> > If the user exits fp then everythign works just fine. If the user tries
> to
> > shutdown or logoff while fp is still running, then my SessionEnding
> handler
> > never gets called. The message just waits in the queue and fp is never
> > forced to exit and the user gets a dialog box claiming that some .NET
> > process isn't ending. (This is the typical dialog seen when a process
> > doesn't play nice at shutdown.) While that dialog is on the screen, if
> the
> > user then shuts down fp, my code will continue to run.
> >
> > So, here's the basic question. Why does the ExitHandler run while the
> > MainThread is suspended, but the SessionEnding Handler does not? (If
you
> > need more info to provide some advice, please let me know...)
> >
> > Thanks.
> >
> > Jerry
> >
> >
>
>



Relevant Pages

  • linker magic: dynamic meta handlers...
    ... dealing with my compiler doing funky codegen magic at link time. ... register allocator/codegen, ...). ... If the handler builds a code fragment which exports the given symbol name, ... The request may also be passed arguments, ...
    (comp.compilers)
  • Re: [tip:perfcounters/core] perf_counter: x86: Fix call-chain support to use NMI-safe method
    ... Writing control registers is serializing, so it's a lot more expensive ... Then how about just writing to the cr2 register *if* it has changed ... fault (the fault handler gives us back an error code). ... And I would not want to touch the page fault handler itself to write the ...
    (Linux-Kernel)
  • Re: Exception Handling...
    ... At FS:the executing code can register an exception handler by providing ...
    (comp.lang.pascal.delphi.misc)
  • Re: Using program as a Service
    ... with the SCM (Service Control Mmmthingy). ... register a handler using RegisterServiceControlHandler. ... When the SCM ...
    (microsoft.public.vc.mfc)
  • Re: Unable to get HID service to run.
    ... your guess might be a good one although I'd still have to figger out which files to register. ... I keep getting a system event that tells me the following: ... Could not start the Human Interface Device Access service on Local Computer. ...
    (microsoft.public.windowsxp.general)

Loading