c# - 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.
Does anyone knows if this is doable in c# .NET?
解决方案
public static bool IsAppRunning()
{
foreach (Process process in Process.GetProcesses())
{
if (process.ProcessName.Contains("Updater"))
{
return true;
}
}
return false;
}
如果你在 while 循环中调用它,它会告诉你 Updater 是否正在运行。
推荐阅读
- spring - 异步注释不进行异步调用
- html - 从数据库中获取特定数据并将其打印到单元格
- pandas - 匹配 Pandas 列中的单词以及基于匹配创建新列时
- python - 如何使用posix消息队列在节点和python之间进行IPC?
- xamarin - Xamarin,我如何包含第一批带有边框的行和列列表,比如将它们组合在一起?
- tensorflow - 使用 Pycharm 连接集群 'ImportError: libcuda.so.1: cannot open shared object file: No such file or directory'
- c# - C# 中的“if”和“#if”有什么区别?
- linux - 批量解压到文件夹路径
- python - 滚动 Instagram 对话框
- typo3 - 如何将上传的图像(使用后端布局中的特定 colPos)映射到图像 Fluid Viewhelper src 属性