我有一個 WPF 視窗,當行程“TeamViewer”啟動時它應該關閉。
不幸的是,我無法建立一個合適的回圈。你能幫助我嗎?
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Process[] pname = Process.GetProcessesByName("TeamViewer");
do
{
this.Close();
}
while (pname.Length > 0);
}
問候 iSteffen
uj5u.com熱心網友回復:
您應該在回圈中查找行程“TeamViewer”,并在找到它的任何實體時退出您的表單。示例代碼,這個監視記事本實體,您可以根據需要對其進行修改。
do
{
Process[] proc = Process.GetProcessesByName("notepad");
if (null != proc)
{
if (proc.Length > 0)
{
//if any notepad process is running, then exit
return;
}
}
//wait for some time, there are other efficient wait mechanisms
Thread.Sleep(500); //wait for half sec
}while(true);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/477563.html
上一篇:用另一列的某些行替換列
