Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have 2 forms in my project: in one the user selects a value from a combobox (form2) and the other one gets the combobox value and uses it(form1).
I start debugging, the form2 (which is called from form1) appears, I select my value and then form1 appears.
Then I get the error"InvailidOperationException was unhandled Object is currently in use elsewhere" from "Program.cs" at
Application.Run(new Form1());

How can I get this error when the form is already open?
How can I resolve it?
This is the strange thing in my code I open form1 only 1 time there's no second one (and I checked my code)
Even stranger: if I delete a part of my code pictureBox1.Image = img; I don't get the error.
Posted
Updated 22-Jun-10 3:17am
v3

It sounds like you are trying to open Form1 a second time when it is already open. Check your code.
 
Share this answer
 
Instead of using Application.Run to re-run the form, simply call form1.Hide() when Form2 is displayed, and when Form2 closes, call form1.Show() again.

There are a couple of other (similar) ways to manage it, but I'll leave you to find those alternatives on your own.
 
Share this answer
 
mostwanted4 wrote:
if I delete a part of my code pictureBox1.Image = img;

Is that happening in a background thread or on the UI thread? I've sometimes seen cross thread exceptions like that thrown up to the call to Application.Run(...) in the Main method.

Does the inner exception shed any light on the problem?

If you attach to the unhandled exception handler:
C#
static void Main(string[] args)
{
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    //...
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    // ...
}


do you get any more useful information?
 
Share this answer
 
I modified my code a little bit and the I got the error "
Bitmap region is already locked" and I found this which solved all my problems. Anyway thank you for your answers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900