c# – Application.Restart()是否为应用程序创建新进程或没有?

前端之家收集整理的这篇文章主要介绍了c# – Application.Restart()是否为应用程序创建新进程或没有?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
据我所知,Application.Restart()重新启动一个应用程序并创建一个新的应用程序实例.此实例是否会在新流程中创建,或者将使用旧流程?

谢谢你的回答.

@H_403_4@

解决方法

它运行在一个新的过程中. documentation似乎有点不清楚该过程是否被重用,但可以通过在启动时在文本框中显示进程ID来验证.
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 Reflector查看是否创建了新进程:

public static void Restart()
{
    // ...
    ExitInternal();            // Causes the application to exit.
    Process.Start(startInfo);  // Starts a new process.
    // ...
}
@H_403_4@ @H_403_4@ 原文链接:https://www.f2er.com/csharp/95192.html

猜你在找的C#相关文章