VB.NET exe that talks to out-of-process COM on activate event bombs when external script AppActivates it

0

I wrote a VB.NET Windows Forms app that requests a string from an out-of-process COM object every time the activate event fires. My form has two tabs, so I need to programmatically flip to the correct tab every time my window gains focus. Works fine, until...

By chance, someone ran a vbscript (yes, script, not exe) that contains:

    Set shell = CreateObject("WScript.Shell")
    shell.AppActivate("Window Title That Matches My App")

This script consistently crashes my app. Usually so badly that the Exception dialog usually can't paint itself. I have to kill it from task manager. Sometimes the Exception is readable. (I also confirmed the exception by attaching to the running exe with Visual Studio). It's: "System.Runtime.InteropServices.COMException (0x8001010D): An outgoing call cannot be made since the application is dispatching an input-synchronous call."

What's really messing with my mind is that my app has multiple instance detection using a mutex, and if an existing instance is running, my own code (compiled) uses VB.NET's own AppActivate keyword, and this does NOT crash my app. It activates the running instance and exits the redundant instance as expected.

The problem seems solely to be triggered by cscript/wscript's AppActivate. I wrote a 3-liner .vbs to confirm this. It's repeatable.

Is there a way to trap or avoid this in my compiled app?

vb.net
com
vbscript
crash
out-of-process
asked on Stack Overflow Jun 18, 2013 by amonroejj

1 Answer

0

It's not clear to me WHY this approach actually fixes the problem, but it DOES work:

  1. Add a timer to the form.
  2. Move all the _Activated code to the timer's _Tick event.
  3. Make the _Activated event start the timer.
  4. Make the _Tick event stop the timer then perform the COM stuff.
answered on Stack Overflow Jun 24, 2013 by amonroejj

User contributions licensed under CC BY-SA 3.0