Exception in method called by Invoke

G

Guest

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?
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top