gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 20:59:30 24 4
gpt4 key购买 nike

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com