我试图逃避一个循环.基本上,如果满足"if"条件,我希望能够退出此循环:
private void CheckLog()
{
while (true)
{
Thread.Sleep(5000);
if (!System.IO.File.Exists("Command.bat"))
continue;
using (System.IO.StreamReader sr = System.IO.File.OpenText("Command.bat"))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
if (s.Contains("mp4:production/CATCHUP/"))
{
RemoveEXELog();
Process p = new Process();
p.StartInfo.WorkingDirectory = "dump";
p.StartInfo.FileName = "test.exe";
p.StartInfo.Arguments = s;
p.Start();
<< Escape here - if the "if" condition is met, escape the loop here >>
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试从特定文件夹启动可执行文件.
我下面的代码奇怪地崩溃了应用程序:
Process p = new Process();
p.StartInfo.WorkingDirectory = "dump";
p.StartInfo.FileName = s;
p.Start();
Run Code Online (Sandbox Code Playgroud)
我调试它,它说它找不到要启动的文件,但文件/文件夹defintly存在,我的语法不好?
下面的代码可以工作,但是没有定义工作的directroy,因此无法找到可执行文件
Process.Start(@"dump\", s);
Run Code Online (Sandbox Code Playgroud) 我目前有一些代码在文本文件中循环查找特定短语。但是,运行此方法时,整个应用程序将锁定。我想是因为它在循环,这就是我想要的。
我希望这种情况在后台发生,因此常规方法和用户与应用程序的交互仍然可以完成。
如何做到/改善呢?
private void CheckLog()
{
while (true)
{
// lets get a break
Thread.Sleep(5000);
if (!File.Exists("Command.bat"))
{
continue;
}
using (StreamReader sr = File.OpenText("Command.bat"))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
if (s.Contains("mp4:production/"))
{
// output it
MessageBox.Show(s);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 是否Process.Start
可以启动启动过程并将其发送到"屏幕背面",例如屏幕上所有其他打开的窗口后面?