如何使用C#立即重启来保持活动进程或阻止窗口应用程序终止? [英] How to Keep alive processes or preventing window app termination with immediate restart using C# ?

查看:168
本文介绍了如何使用C#立即重启来保持活动进程或阻止窗口应用程序终止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成为一个窗口应用程序,但任何budy去任务管理器采取它结束过程所以我的应用程序工作关闭。所以任何想法如何保持活动进程或阻止窗口应用程序终止立即重启。

解决方案





很简单:



  private   void  StartProcess( string  fileName)
{
var process = new Process();
process.StartInfo = new ProcessStartInfo(fileName);
process.EnableRaisingEvents = true ;
process.Exited + = new EventHandler(process_Exited);
process.Start();
}

private void process_Exited( object sender,EventArgs e)
{
MessageBox.Show( Process closed);
}





有关您可在此处找到的流程的更多信息:

http://msdn.microsoft.com/pl-pl/library/system .diagnostics.process%28v = vs.110%29.aspx [ ^ ]



希望它可以帮到你。



[更新]

对不起,我没有仔细阅读你的问题。但我的回答可能会为您提供解决方案。您可以监视应用程序何时关闭并重新启动它。许多应用程序(或服务)使用类似的解决方案。



创建将由您的应用程序启动的简单代理(监视器)应用程序。启动后的代理(监视器)将找到您的主要申请流程并将继续关注它。如果用户关闭您的主应用程序代理将重新启动它。



或者您可以在主窗口中启动您的应用程序关闭事件:

< pre lang =cs> private void MainForm_FormClosed( object sender,FormClosedEventArgs e)
{
StartProcess( Your_APP_ExePath);
}





您可以保存一些设置以在重启后恢复应用程序状态。



希望这次真的可以帮到你:)


i become one window application but any budy go to task manager take it end process so my apps working close. so any idea how to Keep alive processes or preventing window app termination with immediate restart.

解决方案

Hi,

It's simple:

private void StartProcess(string fileName)
{
    var process = new Process();
    process.StartInfo = new ProcessStartInfo(fileName);
    process.EnableRaisingEvents = true;
    process.Exited += new EventHandler(process_Exited);
    process.Start();
}

private void process_Exited(object sender, EventArgs e)
{
    MessageBox.Show("Process closed");
}



More informations about processes you will find here:
http://msdn.microsoft.com/pl-pl/library/system.diagnostics.process%28v=vs.110%29.aspx[^]

Hope it helps you.

[Update]
Sorry, I didn't read too carefuly your question. But my answer may have a solution for you. You can monitor when your application was closed and restart it . Many applications (or services) uses similar solution.

Create simple agent (monitor) application which will be started by your application. Agent (monitor) after start will find your main application process and will keep and eye for it. In case user closes your main application agent will restart it.

Or you can start your application in you main window Closed event:

private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
    StartProcess("Your_APP_ExePath");
}



You can save some settings to restore application state after restart.

Hope this time will really help you :)


这篇关于如何使用C#立即重启来保持活动进程或阻止窗口应用程序终止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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