简体   繁体   English

两次运行相同的C#应用​​程序

[英]Running same C# application twice

The application is a form application and it is too complicated. 该应用程序是一个表单应用程序,它太复杂了。 It is mostly used to connect to a database with an user interface. 它主要用于通过用户界面连接到数据库。 It also uses third party dlls. 它还使用第三方dll。

I copied my VS C# application`s bin folder to my desktop. 我将VS C#应用程序的bin文件夹复制到了桌面上。

"C:\\Users\\asd\\Desktop\\bin" “C:\\用户\\ ASD \\桌面\\ BIN”

After that, I made some changes in my solution and building it, I again copied the application`s bin file under C:\\; 之后,我对解决方案进行了一些更改并构建了该解决方案,然后再次将应用程序的bin文件复制到C:\\;下。

"C:\\bin" “C:\\ BIN”

Now when I run "C:\\Users\\asd\\Desktop\\bin\\Debug\\LIVE.exe" and let it remain open I can`t run "C:\\bin\\Debug\\LIVE.exe" . 现在,当我运行“ C:\\ Users \\ asd \\ Desktop \\ bin \\ Debug \\ LIVE.exe”并保持打开状态时,我将无法运行“ C:\\ bin \\ Debug \\ LIVE.exe” There is no error when I try to open the second .exe file. 当我尝试打开第二个.exe文件时没有错误。 It simply does nothing. 它根本什么也没做。

I want both of the applications to be open at the same time. 我希望同时打开两个应用程序。

Depending on the application, there are ways to prevent execution of a second instance (I have actually implemented the described behaviour in production code) so check the production specs of the application to see if that's a desired behaviour on client machines. 根据应用程序的不同,有一些方法可以防止执行第二个实例(实际上我已经在生产代码中实现了所描述的行为),因此请检查应用程序的生产规格,以了解这是否是客户端计算机上的理想行为。

Because it's using a database connection and third party DLLs, there may be other specific limitations in place preventing proper execution, so check whether any exceptions are being cuaght by hooking into the FirstChanceException (WARNING: Never use this code outside a debug context!) 由于它使用的是数据库连接和第三方DLL,因此可能存在其他特定限制,无法正常执行,因此请通过挂入FirstChanceException检查是否有任何异常(警告:切勿在调试上下文之外使用此代码!)

#if DEBUG
static Program()
{
    AppDomain.CurrentDomain.FirstChanceException += (sender, e) => { };
}
#endif

Insert this into your Program class, or whichever class houses the Main method (and rename it if it's not Program of course) and then breakpoint the opening of the handler - this will often catch lots of exceptions you're better off not worrying about, but it may also clue you in if there is a problem keeping your code from starting. 将其插入到您的Program类中,或者将其中一个包含Main方法的类(如果不是Program ,则将其重命名),然后断点处理程序的打开位置-这通常会捕获很多异常,您最好不要担心,但是如果在阻止代码启动时遇到问题,它也可能会提示您。

As always, make sure to run this from within VS's Debug, so as to see any exceptions as they occur. 与往常一样,请确保从VS的Debug中运行此程序,以便在发生异常时查看它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM