我有以下代码:
public partial class Form1 : Form
{
// our config
public bool runBot, afkModeToggle, shutdownPcToggle = false;
public int roundsToPlay, minsToPlay, waitInLobbyFor, waitInDeathScreenFor;
public void addToLogs(string logmsg)
{
richTextBox1.AppendText("\r\n" + logmsg);
richTextBox1.ScrollToCaret();
}
public void startsoftware()
{
runBot = true;
addToLogs("[" + DateTime.Now + "] Bot has started");
label22.Text = " RUNNING" + runBot;
label22.ForeColor = System.Drawing.Color.DarkGreen;
}
public void pausesoftware()
{
runBot = false;
addToLogs("[" + DateTime.Now + "] Bot has been paused");
label22.Text = " PAUSED" + runBot;
label22.ForeColor = System.Drawing.Color.Crimson;
if (checkBox3.Checked)
{
Process.Start("shutdown", "/s /t 0");
}
}
public bool processrunning()
{
Process[] pname = Process.GetProcessesByName("notepad");
if (pname.Length == 0)
{
label23.Text = "process Not Found";
label23.ForeColor = System.Drawing.Color.Crimson;
return false;
}
else
{
label23.Text = "process Found";
label23.ForeColor = System.Drawing.Color.DarkGreen;
return true;
}
}
//
// form follows
//
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
while(runBot == true)
{
if(processrunning() == true)
{
}
}
}
private void button1_Click(object sender, EventArgs e)
{
startsoftware();
}
private void button2_Click(object sender, EventArgs e)
{
pausesoftware();
}
}
它是通过 Visual Studio 构建的基本形式。当我单击按钮 1 时,它只会冻结软件,而您无法单击其他任何内容。我已经将其追溯到这一点 - 如果我注释掉函数runBot = true内部startsoftware,它将起作用,但是该行会导致冻结。
我在这里遗漏了什么?
慕桂英4014372
LEATH
相关分类