我要写两个小程序。
(1)是一个负责合其他机子通讯的程序,其在退出时要运行几句代码。我写在form——closing中了。调试没问题
(2)是一个和设备数据交换(串口)的程序,其在收到设备上传的关机或重启指令时,能够执行自己的关机和重启。在关机指令只能由程序2发出,但是我想让程序1在被杀掉之间能够最后form-closing中的语句。
如何处理?谢谢。
两个程序都是C#写的。
(1)是一个负责合其他机子通讯的程序,其在退出时要运行几句代码。我写在form——closing中了。调试没问题
(2)是一个和设备数据交换(串口)的程序,其在收到设备上传的关机或重启指令时,能够执行自己的关机和重启。在关机指令只能由程序2发出,但是我想让程序1在被杀掉之间能够最后form-closing中的语句。
如何处理?谢谢。
两个程序都是C#写的。
关键是程序1结束时要把自己的IP释放掉,要不然会有问题。
所以最好其能在被关掉时释放一下。
而1收到关机命令后我只能把一些进程杀掉,然后通过执行API的关机指令就关机了,如何能通知2一下呢。
2程序发送给1程序监听端口关闭命令,并监视1进程是否退出,如果退出关机也可以用进程间通信解决呀,邮件槽,共享内存等都可以呀
A进程收到关机命令,通知B进程关闭,等待B回复,收到B的关闭回复,A关机,如果等待超时,A关机
//form_closing()这个说到底也是个函数,当正常的来用就可以了
准备用Herolegend() ( )的方法试试.
The TerminateProcess function is used to unconditionally cause a process to exit. Use it only in extreme circumstances. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess. TerminateProcess causes all threads within a process to terminate, and causes a process to exit, but DLLs attached to the process are not notified that the process is terminating. Terminating a process causes the following: All of the object handles opened by the process are closed.
All of the threads in the process terminate their execution.
The state of the process object becomes signaled, satisfying any threads that had been waiting for the process to terminate.
The states of all threads of the process become signaled, satisfying any threads that had been waiting for the threads to terminate.
The termination status of the process changes from STILL_ACTIVE to the exit value of the process.
Terminating a process does not cause child processes to be terminated. Terminating a process does not necessarily remove the process object from the system. A process object is deleted when the last handle to the process is closed.
{
Process down = new Process();
down.StartInfo.FileName = "shutdown";
down.StartInfo.Arguments="-s -t 60";
down.StartInfo.UseShellExecute = false;
down.StartInfo.RedirectStandardError = true;
down.StartInfo.RedirectStandardInput = true;
down.StartInfo.RedirectStandardOutput = true;
down.Start();
}
A要传信息给C,必需先进行B的验证..B验证成功转交给C.验证不成功转交给A重复发送.
不知道对你有用不
http://community.csdn.net/Expert/topic/5654/5654574.xml?temp=.9189417揭贴给分,多谢大家帮忙
你的问题是在程序2调用关机命令时,因为因为程序1的进程被强行结束,所以无法执行form_closing中的语句。你只要在收到关机或重新启动的命令前,向程序1发个关闭的指令,在程序2中检查程序1关闭后,再关机或重新启动