When my CF1 application starts up, it loads its main form:

static void Main()
{
try
{
Application.Run(new MainForm());
}
catch(Exception e)
{
MessageBox.Show("Unhandled error: " + e.Message, "My App",
MessageBoxButtons.OK, MessageBoxIcon.Hand,
MessageBoxDefaultButton.Button1);
}
}

In its OnLoad method, the new form starts a thread. When the thread is done,
it calls Invoke(). The invoked method is throwing an exception. The exception
is caught by the try/catch block above in main, and the application exits.

It appears the thread is still running, presumably blocking on the Invoke.
(I put a breakpoint after the Invoke, and it's never hit. The debugger
doesn't close either.)

Can anyone tell me what I'm doing wrong here? What's the correct way to
approach this?

Regards,
David

PS- As an aside, on some devices (e.g., iPaq running 2003SE) the MessageBox
above beeps and immediately closes. Why is that?

RE: Exception in method called by Invoke by guiness

guiness
Thu Sep 13 09:58:01 PDT 2007

Ugh. Never mind. The moment I posted that, it came to me...

I wrapped the invoked method with its own try/catch block, moved the
MessageBox.Show() there, and added a call to Application.Exit(). Problem
solved.

--
David


RE: Exception in method called by Invoke by srhartone

srhartone
Sun Sep 16 14:12:01 PDT 2007

On a side note, it is better practice to hook into the
AppDomain.UnhandledException. see here for more info:
http://msdn2.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx

--
Simon Hart
http://simonrhart.blogspot.com


"David" wrote:

> When my CF1 application starts up, it loads its main form:
>
> static void Main()
> {
> try
> {
> Application.Run(new MainForm());
> }
> catch(Exception e)
> {
> MessageBox.Show("Unhandled error: " + e.Message, "My App",
> MessageBoxButtons.OK, MessageBoxIcon.Hand,
> MessageBoxDefaultButton.Button1);
> }
> }
>
> In its OnLoad method, the new form starts a thread. When the thread is done,
> it calls Invoke(). The invoked method is throwing an exception. The exception
> is caught by the try/catch block above in main, and the application exits.
>
> It appears the thread is still running, presumably blocking on the Invoke.
> (I put a breakpoint after the Invoke, and it's never hit. The debugger
> doesn't close either.)
>
> Can anyone tell me what I'm doing wrong here? What's the correct way to
> approach this?
>
> Regards,
> David
>
> PS- As an aside, on some devices (e.g., iPaq running 2003SE) the MessageBox
> above beeps and immediately closes. Why is that?
>