Click here to Skip to main content
12,889,448 members (51,025 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET C#4.0 .NET4
I have a Windows Forms application that has UI which contains different forms that the user is navigated to during his work. At a certain point When navigating forward the next form is loaded in an entirely new instance of the appllication while the previous form stays in another instance although it has been hidden through the code. Even more - an exception saying "Cannot access a disposed object." is thrown. First - the previous form is only hidden - not closed so the object should not have been disposed. And even if the previous form has really been disposed how is it possible to still be present in another instance of the application. This happens sometimes on Windows XP, but never on Windows 7. Does anyone know how to fix this?
Posted 15-Feb-12 2:03am
Updated 15-Feb-12 3:04am
ryanb31 15-Feb-12 8:04am
No idea what you are saying.
Rajeev Jayaram 15-Feb-12 8:18am
Do you refer to instance as a seperate screen? Are you using desktop or web application? If web application, what browser in Xp and Win 7?
Use "Improve question" to update your question.
Dave Kreskowiak 15-Feb-12 8:20am
We don't have any idea what you did to determine that this is the case or what you did to accomplish this so it's impossible to say how to fix it.

No, navigating to another window will NOT launch a second process and pick up where your first app left off. It just never happens.

I suspect you may be looking in the TaskBar at the icons that show for each window and not looking in TaskManager at the Process list.
Angel_dust 15-Feb-12 8:52am
When I look in TaskManager at the process list there is only one process of the application but in the task bar there are two different application icons and two different applications in the Task Manager but both point to the same process when I use the "go to process" option.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You've contradicted yourself in your last comment.

You said:
When I look in TaskManager at the process list there is only one process of the application

and then you said:
and two different applications in the Task Manager but both point to the same process

OK. I think I know what you're seeing. While in Visual Studio, there is a process that is always running with the same name as your resulting executable. This is the Visual Studio Hosting Process. When you debug your app, VS will launch your resulting .EXE, along with the hosting process with nearly the same name.

In TaskManager you'll see, for example, MyApplication.exe and usually right next to it, you'll see MyApplication.vshost.exe. But since the default column width in TaskManager is pretty narrow, you might now see the ".vshost.exe" portion of the image name, causing you to think that there are two copies of your app running.

As the for the Tab Bar, those are not application icons. Those are window icons. If your app has multiple Forms, you can set them so that they can show an icon in the Task Bar or not using the ShowInTaskbar property. Your forms probably have this property set to True, so when you launch a second form, you're seeing the icon for the new form in the Taskbar right next to the icon for the original form in your app.
A. Karthick Arun 16-Feb-12 1:24am
Your explanation seems OK. but, you missed out the cause of throwing exception "Cannot access a disposed object.". Please share if you've any ideas.
Dave Kreskowiak 16-Feb-12 7:50am
So what are you doing to launch a second instance?? The only case where that would happen automatically is if a Windows Service is configured to relaunch itself upon failure. Windows Forms app do not do that at all.

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

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 15 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100