Winforms/ActiveX cross threaded calls

1

I have an application wherein I am hosting multiple types of content (images, PowerPoint presentations, videos etc) in a kiosk-type app. The user has to be able to page back and forth between these bits of content, preferably using gestures of the touchscreen on the kiosk, i.e. tap one side of the screen to go forward, the other side to go back.

Unfortunately, the controls that display the content could have further nesting, so I'm using a Win32 mouse hook to capture mouse clicks, checking if they are within a specified region. This works great. Unfortunately these click events are (indirectly) calling methods on the ActiveX control I'm using to host PP presentations (DSOFramer), and it's causing this nasty COM exception:

An outgoing call cannot be made since the application is dispatching an input-synchronous call. (Exception from HRESULT: 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL))

My best guess is that the low level mouse hook is calling from a different thread, because if I make the call directly from the Winforms UI thread, there's no problem. I tried the standard Winforms Invoke/BeginInvoke with no success.

winforms
activex
multithreading
asked on Stack Overflow Jul 12, 2010 by Matthew Olenik

1 Answer

1

I was using the typical Winforms cross-thread pattern:

if(InvokeRequired)
{
    Invoke(new Action(DoStuff));
}
else
{
    DoStuff();
}

Of course the control I'm calling from has no idea of the AX control, so I need to explicitly invoke the action. It also needs to use BeginInvoke, so the above becomes:

BeginInvoke(new Action(DoStuff));

Works now. Oops!

answered on Stack Overflow Jul 12, 2010 by Matthew Olenik

User contributions licensed under CC BY-SA 3.0