应用程序的两个实例在运行时出现 [英] Two instances of the application appear during runtime

查看:76
本文介绍了应用程序的两个实例在运行时出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows Forms应用程序,该应用程序的UI包含用户在工作期间导航到的不同表单.在某个特定点向前导航时,下一个表单将被加载到一个全新的应用实例中,而前一个表单将被保留在另一个实例中,尽​​管该表单已被代码隐藏了.更重要的是-一个异常提示无法访问已处置的对象".被抛出.首先-以前的表单仅是隐藏的-不会关闭,因此不应处置该对象.而且,即使先前的表格已被真正处理掉,也可能仍然存在于该应用程序的另一个实例中.在Windows XP上有时会发生这种情况,而在Windows 7上却不会发生.

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?

推荐答案

您在最近的评论中与自己矛盾. br/>
你说:
当我在TaskManager中的进程列表中查看时,应用程序只有一个进程

然后你说:
和任务管理器中的两个不同的应用程序,但都指向相同的过程

好的.我想我知道你在看什么.在Visual Studio中,有一个进程始终与您生成的可执行文件同名运行.这是Visual Studio托管过程.当您调试应用程序时,VS将启动您生成的.EXE,以及几乎相同名称的托管过程.

例如,在TaskManager中,您将看到My​​Application.exe,通常在其旁边,您将看到My​​Application.vshost.exe.但是,由于TaskManager中的默认列宽度非常窄,因此您现在可能会看到图像名称的".vshost.exe"部分,使您认为应用程序有两个副本正在运行.

与标签栏一样,这些也不是应用程序图标.这些是窗口图标.如果您的应用程序具有多个窗体,则可以对其进行设置,以便它们可以在任务栏中显示图标,也可以不使用ShowInTaskbar属性.您的表单可能将此属性设置为True,因此,当您启动第二个表单时,您会在任务栏中在应用程序中原始表单的图标旁边看到新表单的图标.
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.


这篇关于应用程序的两个实例在运行时出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆