Re: timer queue

From: John B (B_at_discussions.microsoft.com)
Date: 02/26/05


Date: Fri, 25 Feb 2005 19:21:03 -0800

Thanks for the reply. I did end up creating a hidden window that works ok.
Incidently, calling QI for IUnknown doesn't work as a test for the existence
of the app. The call succeeds even after eg Word has been closed. I am
assuming that the proxi is doing some shortcutting on some calls. However
Invoke on a property does fail with "rpc not available" after the app is
closed.

"Alexander Nickolov" wrote:

> Most likely both components run in the same apartment, so the
> second holds a direct pointer to the first. Therefor e, COM is
> not in the loop to safeguard you against blunders and the call
> from 2 to 1 on the timer thread succeeds. Ordinarily you
> cannot make any COM calls from this timer thread since COM
> is not initialized on it.
>
> Assuming you have STA components, I suggest you create
> a hidden window and use SetTimer/KillTimer and handle
> WM_TIMER from that hidden window (don't use global
> timers since it's hard to get back into your object).
>
> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD
> email: agnickolov@mvps.org
> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================
>
> "John B" <John B@discussions.microsoft.com> wrote in message
> news:8FDBF2A1-22F9-429D-9799-129FC6784155@microsoft.com...
> >I am trying to use CreateTimerQueue in an ATL class and am having trouble
> > with some threading issues. I am using an inproc class to launch an App
> > eg
> > Word and then launching another class as an event sink for the app. These
> > two classes use custom interfaces to communicate. The structure is as
> > follows
> >
> > Class 1 coCreate app (eg Word) and uses type infor to look for events eg
> > Quit.
> > Class 1 coCreate class 2 and passes pUnk1 and pDispApp (Word) in an
> > interface method call. Class 2 calls pUnk1->QI to get custom interface to
> > callback to 1, p1. If app supports Quit, 2 uses pDispApp->QI connection
> > interfaces and calls Advise. This all works. 2 sinks the events and
> > calls 1
> > using interfacem p1. If the app does not support Quit, 2 calls
> > CreateTimerQueue, etc. The problem comes in the timer callback. I pass
> > 2's
> > "this" ptr as a parameter and static cast to p2 in the static timer
> > callback.
> > In the callback, p2-> member values are ok, p2->p1 works but p2->pDispApp
> > gets a "marshalled on wrong thread" error. I want to use the pDispApp to
> > take a quick peek, eg p2->pDispApp->QI( IUnknown) to see if the App is
> > still
> > alive. The pDispApp works in the (nonstatic) member methods of p2 without
> > a
> > problem. Why does p2->p1 work and p2->pDispApp not work in the timer
> > callback? If the callback is on a different thread, why does p2->p1 work
> > and
> > if the callback is on p2's thread, why doesn't p2->pDispApp not work?
> > Another question is whether there a better way to set up a timer that
> > would
> > avoid this problem?
>
>
>



Relevant Pages

  • Re: msflexgrid with ctrl-pgup & ctrl-pgdn
    ... It is still possible for your VB app to ... Timer event, which occurs about ten milliseconds after the key was ... Private Sub Form_Unload ... Private Declare Function SetWindowsHookEx Lib "user32" _ ...
    (comp.lang.basic.visual.misc)
  • Do-Nothing WinForm App Using 4 Threads?
    ... refactoring a multi-threaded GUI app at work and want to be sure it's ... I then added a Windows Timer control to the form and updated a label ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: ldb file
    ... have a timer event set to check the value of the field in the back end to see ... If it indicates the app should be closed, then give the user a 5 ... Is there a way that I can I kick out the ...
    (microsoft.public.access.gettingstarted)
  • RE: ldb file
    ... have a timer event set to check the value of the field in the back end to see ... If it indicates the app should be closed, then give the user a 5 ... quit the application. ...
    (microsoft.public.access.gettingstarted)
  • Re: Disk thrashing with paging file
    ... Your Timer suggestion is a very good idea which I'll try before ... to stop Windows paging out memory. ... user interface app and SQL Server. ... SetProcessWorkingSetSize or VirtualLock APIs make a difference? ...
    (microsoft.public.vb.winapi)