I have a Inproc COM Server from a 3rd party. One of the functions I call will display a error message dialog box if it traps a specific type of error. The issue is I am trying to process data in bulk, and the data source I am using is causing that error dialog to pop up a lot. This would not be a issue if it spawned 1000 dialog boxes, but instead it blocks and the function does not return until you press OK.
How can I suppress the dialog from showing up, or programmatically press OK?
Here is a copy of the call stack as it is waiting for me to press OK
[Managed to Native Transition] > System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) Line 2198 + 0x1e bytes C# System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) Line 3422 + 0x1b bytes C# System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Line 3306 + 0xc bytes C# System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) Line 1495 + 0x31 bytes C# UniversalDataImporter.exe!UniversalDataImporter.Program.Main() Line 18 + 0x1d bytes C# [Native to Managed Transition] [Managed to Native Transition] mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) Line 2023 + 0x18 bytes C# Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x27 bytes mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) Line 68 + 0x27 bytes C# mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 581 + 0xd bytes C# mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 530 + 0xd bytes C# mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 519 + 0xe bytes C# mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() Line 105 + 0x20 bytes C# [Native to Managed Transition]
I doubt it will help (there are no options to disable the message box, events to subscribe to, or other overloads to the function) but here is the calling code.
for (int i = 1; i <= recordCount; i++)
{
//If the dialog shows up the following line blocks till you press OK.
var values = _comServer.GetValues(fileHandle, i);
sqlDataConsumer.LoadRow(values);
}
First of all, it would certainly be better if the COM server itself could be turned into mode when it does not let caller down with undesired UI action. Provided that you cannot alter third party component behavior, what you still can do is hooking message processing and forced closing of the message box.
Before doing the call on the third party server, you can install a message hook with
SetWindowsHookEx
andWH_CALLWNDPROC
and your callback will be able to monitor the messages. In particular you will be able to post messages, hook dialog's WindowProc etc. Including certainly programmatic closing of the message box.A message box pumps a message loop. That's something you can take advantage of, it allows you to inject code with Control.BeginInvoke() that runs as soon as the message box appears. You can then use that code to find the dialog window and close it. Add a new class to your project and paste this code:
Sample usage: