是否Application.Restart()创建的应用程序或没有新的进程? [英] Does Application.Restart() creates new process for application or no?
本文介绍了是否Application.Restart()创建的应用程序或没有新的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
据我所知 Application.Restart()
重新启动应用程序并创建一个新的应用实例。请问这种情况下会产生新的过程中,还是老工艺将采用?
As I know Application.Restart()
restarts an application and creates new Instance of an Application. Does this instance will creates in new process, or old process will be used?
感谢您的回答。
推荐答案
它运行在一个新的进程。该文档似乎就有点不清楚的过程是否被重复使用,但它可以通过示出在启动时在文本框的进程ID进行验证。
It runs in a new process. The documentation seems a little unclear on whether or not the process is reused but it can be verified by showing the process ID in a text box at start up.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Application.Restart();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = Process.GetCurrentProcess().Id.ToString();
}
}
您还可以看到使用 .net反射在创建新进程:
You can also see using .NET Reflector that a new process is created:
public static void Restart()
{
// ...
ExitInternal(); // Causes the application to exit.
Process.Start(startInfo); // Starts a new process.
// ...
}
这篇关于是否Application.Restart()创建的应用程序或没有新的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文