我最近使用
本教程。我得到了工作的应用程序,并更改了程序以满足我的需求。我知道您可以通过在CMD中键入“ dotnet run”来启动该过程,并通过在CMD中按CTRL + C来阻止它。
但是,如何通过C#代码自动启动和终止该过程呢?
我希望在另一个程序中调用时运行的过程,然后在24小时后终止。
提前致谢。
I've recently set up my first influxdb using
https://www.influxdata.com/blog/getting-started-with-c-and-influxdb/
This tutorial. I got the application to work and changed the program to fit my needs. I'm aware that you can start the process by typing "dotnet run" in CMD and stop it by pressing ctrl + c in CMD.
But how could you automatically start and terminate the process via c# code?
I'd like the process to run when called by another Programm and then be terminated after 24 hours.
Thanks in advance.
发布评论
评论(1)
您的问题应减少到如何开始和安排关闭过程。
“ nofollow noreferrer”>计时器类
可以使用。
在我的演示中,
open(button)
将在path
中打开.txt
文件。关闭(按钮)
将开始5S倒计时,以关闭Notepad
程序。您可以根据需要更改它。
.NET 4.8框架Winform在此处使用。
当然,您还可以使用控制台应用程序来完成此操作。
以下是我的代码:
输出:
Your question should be reduced to how to start and schedule a process to shut down.
Timer class and
ProcessStartInfo.CreateNoWindow class can be used.
In my demo,
open(button)
will open the.txt
file in thepath
.close(button)
will start a 5s countdown to close thenotepad
program.You can change it according to your needs.
The .net 4.8 framework winform is used here.
Of course, you can also use the console application to complete this.
Below is my code:
Output: