c# - 使用命令行参数的 Application.Restart()

标签 c# application-restart

我有一个可以传递命令行参数的应用程序。一段时间后,我想重新启动我的应用程序,向其传递与第一次启动应用程序时相同的命令行参数。

private void frmSetTime_Load(object sender, EventArgs e)
{
    try
    {
        string[] cmds = System.Environment.GetCommandLineArgs();
        //Here i gets Command Line Arguments
    }
    catch (Exception ex)
    {
        MessageBox.show(ex.message);
    }
    finally
    {
        GC.Collect();
    }
}

public void ExecuteLogic(Object obj)
{
    try
    {
        //My set of Statements
        Therad.sleep(5000);
        ExecuteLogic(obj);
    }
    catch (Exception ex)
    {
        MessageBox.show(ex.message);
    }
    finally
    {
        GC.Collect();
        ApplicationRestart();
    }
}

private void ApplicationRestart()
{
    try
    {
        if (Process.GetCurrentProcess().WorkingSet64 >= 10000000)
        {                         
            Application.Restart();                    
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.message);
    }
}

最佳答案

这会自动发生。您无需更改任何内容。

来自 Application.Restart 的文档:

If your application was originally supplied command-line options when it first executed, Restart will launch the application again with the same options.

关于c# - 使用命令行参数的 Application.Restart(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15490029/

相关文章:

c# - 无法在 WindowsUniversal 应用程序中使用 WebView 控件打开 .html 文件

c# - 如何根据任何值隐藏gridview中的任何行

c# - .net 自定义配置如何不区分大小写地解析枚举 ConfigurationProperty

c# - Akka.Net 远程处理 : ActorSelection vs. IActorRef

r - 高级错误处理

shell - 如何创建脚本以在 Tomcat 7 上自动重启 Web 应用程序

java - 如何让你的java应用程序自动重启

java - 单击按钮时如何重新启动 JavaFX 应用程序

android - 后台模式总是从 INDEX 重新启动后,Android 5.1 上的 CORDOVA/PHONEGAP

c# - 如何设置 ASP.Net 3.0 Core Web API 项目来使用 AutoFac 和 NLog?