c#.net + .exe通过进程功能集成 [英] c#.net +.exe integration by process function

查看:62
本文介绍了c#.net + .exe通过进程功能集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi ..

我有一个非常简单的问题需要注意.我有2个.net项目pro1,pro2.现在在pro1中,我有一个菜单"connect",我想在其中执行pro2的输出,然后选择pro2.exe并将其粘贴到pro1文件夹中,然后从pro1中添加引用,然后按Process.Start("Pro2.exe")调用.exe.现在,在调试pro1时,它运行良好.但是它只运行1次,其他任何时间则显示win32异常.或者,如果有任何状态更改(例如,如果我在任何状态更改的编辑器中打开文件),则其给出异常.可能出什么问题了?

hi..

I have a very simple problem tht needs attention. I have 2 .net projects pro1, pro2. Now in pro1 I have a menu "connect" where I wish to execute the output of pro2 and I choose the pro2.exe and paste it in the pro1 folder and from pro1 i add reference and I call the .exe by Process.Start("Pro2.exe"). Now its running fine when pro1 is debugged. BUT it only runs for 1 time and for any other time it shows an win32 exception. Or if there is any state change(like if I open a file in the editor of any state change) then its giving exceptions. What may go wrong?

推荐答案

在我看来,主要的问题是运行通过运行pro2.exe的进程的第二个实例.可能有很多原因,因为您没有提供足够的详细信息,但这是非常常见的,尤其是当您尝试组织流程之间的流程间通信时:许多这样做的方式都暗示了参与流程之一的唯一性.

出于实验目的,请尝试终止第一个实例-您可以访问Process.Start返回的已启动Process的实例,因此可以使用Process.Kill.

我无法告诉您如何解决"此问题,因为除非您共享所有此活动的目的,否则这不是问题.您尝试做的事情很奇怪,通常根本没有做.如果您想要一个宿主进程,能够使用其可执行文件动态运行"扮演插件或应用程序"角色的其他.NET程序集的代码,则您使用的方式不正确.然后,您不必在其他过程中运行.如果使用System.Reflection.Assembly动态加载程序集,则可以在同一进程中运行它们(尽管可能在单独的线程中).如果您需要多次执行此操作,则应将其加载到新的 Application Domain 中(请参阅System.AppDomain),因为可以卸载AppDomain,但是没有办法从过程中卸载程序集.再说一次,我不再确切地做什么,是您详细解释您的目的.

抱歉,如果没有回答您的问题.在这种情况下,您需要提供更多信息.请显示启动该流程并获取其输出"的代码(以及您尝试用于在流程之间进行通信的所有其他方式).捕获您得到的异常,进行完整的转储(包括其堆栈和所有内部异常,以递归方式),将转储保存在文件中并在您的问题中发布.

重要的!不要将您的后续信息发布为答案".请改用改善问题"或添加评论".

—SA
It seems to me the major problem is running the second instance of the process started by running pro2.exe. There can be many reasons for that as you did not provide enough detail, but this is very usual, especially when you try to organize inter-process communication between processes: many ways of doing that imply uniqueness of one of the participating process.

For experimental purpose, try to terminate first instance — you have access to the instance of the started Process returned by Process.Start, so you can use Process.Kill.

I cannot tell you how to "fix" this problem, because this is not a problem unless you share the purpose of all this activity. What you''re trying to do is very weird and usually are not done at all. If you want to have a host process which is able to "run" dynamically code of other .NET assemblies playing the role of plug-ins or "applications" using their executable files, you''re not using right way. You don''t have to run then in different process. You can run them in the same process (albeit possibly in a separate thread) if you load assembly dynamically using System.Reflection.Assembly. If you need to do in more than once, you should load it in a new Application Domain (see System.AppDomain), because you can unload AppDomain, but there is no a way to unload assembly from the process. Again, I''ll no more exactly what to do, is you explain your purpose in detail.

Sorry if this did not answer your question. In this case, you need to provide more information. Please show the code of starting the process and getting its "output" (as well as all other ways you''re trying to use to communicate between processes). Catch exception you got, make a full dump (including its stack and all inner exceptions, recursively), save the dump in file and post in in your question.

Important! Do not post your follow-up information as Answer. Use "Improve question" or "Add comment" instead.

—SA


这篇关于c#.net + .exe通过进程功能集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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