Reputation: 6037
Application.Run(form);
Actually I tried to call this from my project. I got this exception. How to solve it? I have already called another Application.Run(frmBind);
in my project.
Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead.
static void Main(string[] args)
{
frmBind = new frmMain();
Application.Run(frmBind);
//args1 = string.Copy(args);
}
This is where I call the Application at first
Now again did it here:
try
{
// Application.Run( form);
form.ShowDialog();
}
Here the exception is thrown.
Upvotes: 2
Views: 6858
Reputation: 158289
You can only call Application.Run once in a thread. Application.Run will (amongst other things) set up the main message loop for the thread, and there can be only one such loop. This is why you get the exception.
If you simply want to display a form, just use form.Show()
or form.ShowDialog()
instead. Note that calling ShowDialog for a form that is already visible will throw an InvalidOperationException as well (but with another message).
Upvotes: 4
Reputation: 421968
It's telling you how to solve it:
form.Show();
or if you want the new form to be modal:
form.ShowDialog();
Upvotes: 7