[英]C# Pause one console application when other console application starts
I have one console application for testing purposes like following: 我有一个用于测试目的的控制台应用程序,如下所示:
static void Main(string[] args)
{
do
{
for (int i = 0; i < 10000000; i++)
{
Console.WriteLine("Doing some endless loop");
Console.WriteLine(i.ToString());
}
} while (true);
}
As you can see the code is very basic, and I've set it up to endless loop in order to test what I would like to achieve. 如您所见,代码非常基础,为了测试我想要达到的目的,我将其设置为无限循环。
The other console application is called "Updater" and I would like to to pause the "EndlessLoop" console application once the "Updater" application is started. 另一个控制台应用程序称为“ Updater”,一旦“ Updater”应用程序启动,我想暂停“ EndlessLoop”控制台应用程序。
Does anyone knows if this is doable in c# .NET? 有谁知道这在c#.NET中是否可行?
Not easy to communicate between 2 application 2个应用程序之间不容易沟通
One proposition: When your console Updater
starts, you create a file in folder C:\\Temps\\token.txt
. 一个建议:当控制台
Updater
启动时,您在文件夹C:\\Temps\\token.txt
创建一个文件。 Then, if your console EndlessLoop
detects a file names token.txt
in C:\\Temps
, you pause EndlessLoop
然后,如果控制台
EndlessLoop
在C:\\Temps
检测到文件名token.txt
,则暂停EndlessLoop
public static bool IsAppRunning()
{
foreach (Process process in Process.GetProcesses())
{
if (process.ProcessName.Contains("Updater"))
{
return true;
}
}
return false;
}
If you call this in while loop it tells you if Updater is running or not. 如果在while循环中调用它,它将告诉您Updater是否正在运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.