M
Myron Marston
When an unhandled exception occurs in my low-level framework, I want to
display a message to the user using MessageBox.Show(). However,
depending on where the exception is caught, this sometimes locks my
application. Specifically, I tried wrapping my Sub Main in try-catch
blocks, and it blocked. I can understand how this would occur, since
at that point it is no longer in the message pump and will not process
messages. I tried to fix this by moving the try-catch up the call
stack a level and put it in ApplicationEx.Pump(), like so:
private static bool Pump()
{
ArrayList MyMessageFilters = new ArrayList();
// there are, so get the top one
if (GetMessage(out msg, IntPtr.Zero, 0, 0))
{
try
{
// the usual code goes here
}
catch (Exception ex)
{
MessageBox.Show("Exception: " & ex.Message);
}
}
else
{
return false;
}
return true;
}
However, my application is still blocking when the catch is reached and
MessageBox.Show is displayed. It seems like the message pump should
continue, but it's not. Why not? Is there a best practice for where
to put the outermost exception handler in a CF app?
display a message to the user using MessageBox.Show(). However,
depending on where the exception is caught, this sometimes locks my
application. Specifically, I tried wrapping my Sub Main in try-catch
blocks, and it blocked. I can understand how this would occur, since
at that point it is no longer in the message pump and will not process
messages. I tried to fix this by moving the try-catch up the call
stack a level and put it in ApplicationEx.Pump(), like so:
private static bool Pump()
{
ArrayList MyMessageFilters = new ArrayList();
// there are, so get the top one
if (GetMessage(out msg, IntPtr.Zero, 0, 0))
{
try
{
// the usual code goes here
}
catch (Exception ex)
{
MessageBox.Show("Exception: " & ex.Message);
}
}
else
{
return false;
}
return true;
}
However, my application is still blocking when the catch is reached and
MessageBox.Show is displayed. It seems like the message pump should
continue, but it's not. Why not? Is there a best practice for where
to put the outermost exception handler in a CF app?