I have a VB6 application that uses several components written in .net. The application must shutdown gracefully when windows is shut down. The problem is that if the .net part of the code is displaying a window, the application displays the message "Cannot Quit" and fails to exit. (It is then terminated by the OS)
I've managed to reproduce this in a simplified app.
The .net code creates a WPF window and displays it using ShowDialog()
[Guid("5F3D0B23-2196-4082-B9DE-B208C61FE89F")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IComShutdownTest
{
[DispId(1)]
void RunTest();
}
[Guid("E6613EDD-D51B-42c0-AA5B-5961AB28D063")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("ShutdownTest")]
public class ShutdownTest : IComShutdownTest
{
public ShutdownTest()
{ }
public void RunTest()
{
TestWindow testWindow = new TestWindow();
bool? dialogResult = testWindow.ShowDialog();
}
}
As you can see the .net call blocks (and is on the GUI thread) and I suspect this may be the root of the problem, but I can't go round making all my calls non-blocking. I would have assumed that when the OS shutsdown, that the all of the open application windows are terminated.
The VB6 application loads and displays the .net form from a button click.
Private Sub ButtonTest_Click()
LogEventToFile "Starting"
Dim dotNetTestObject As ShutdownTest
LogEventToFile "Creating"
Set dotNetTestObject = New ShutdownTest
LogEventToFile "Running"
dotNetTestObject.RunTest
LogEventToFile "Done"
End Sub
If you attempt to shutdown the PC while the .net form is on the screen it fails. The "Cannot quit" message box looks like this.
To recreate this you must mark the assembly as com visible (in the assemblyinfo.cs)
[assembly: ComVisible(true)]
and you must set the Project->Properties>Build tab to "Register for COM interop"
I also registered the compiled assembly with:
regasm ShutdownTestLibrary.dll /tlb ShutdownTestLibrary.tlb
Has anyone encountered this before and have any suggested solutions.