Application.Restart()与命令行参数

时间:2013-03-19 01:35:43

标签: 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);
    }
}

1 个答案:

答案 0 :(得分:4)

这将自动发生。你不需要改变任何东西。

来自Application.Restart的文档:

  

如果您的应用程序最初在首次执行时提供了命令行选项,则Restart将使用相同的选项再次启动应用程序。

相关问题