标题可能没有意义,因此我将对其进行详细说明。
if (checkbox1.Checked && (RobloxPlayerBeta.exe is open)
{
api.Launch;
}
我想这样做,以便如果选中此复选框并且打开了该过程,则api将启动。
使一个函数查看某个进程是否处于活动状态非常简单。我举了一个小例子给你看。
不要忘记使用以下导入:
使用System.Diagnostics;
这是我正在使用的功能:
public bool IsProcessOpen(string name)
{
Process[] p = Process.GetProcessesByName(name); ///Get the process by a name
if(p.Length == 0) /// if the length of the array is 0, then it means its not running.
{
return false;
}
else /// if its other then 0 it means its its running.
{
return true;
}
}
我通过单击Windows Forms应用程序上的简单按钮来检查答案。我正在使用以下内容:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(IsProcessOpen(textBox1.Text).ToString());
///To test this function, you can try this by changing "textBox1.Text" to "cmd"
///If cmd is not opened, it will return false,
///If cmd is running, it will return True. You can also do this with other processes. For example Chrome
}
如果决定复制此函数,则是if语句应如下所示:
if (checkbox1.Checked == true && IsProcessOpen(RobloxPlayerBeta) == true)
{
api.Launch;
}
希望这可以帮助您。
Twan