我不能为这个方法创建一个线程,因为它只有一个参数。我看到了类似的问题,但我的方法是“分离的”,如果我将变量传递给它,错误表明text当前上下文中不存在该名称(参数名称)。
private void Form1_Load(object sender, EventArgs e)
{
Thread TH = new Thread(PressBind); //I cant make thread for this method
TH.SetApartmentState(ApartmentState.STA);
CheckForIllegalCrossThreadCalls = false;
TH.Start();
}
private void TxBxKTB_TextChanged_1(object sender, EventArgs e)
{
TextBox objTextBox = (TextBox)sender;
string text = objTextBox.Text;
label2.Text = $"the bind key is {text}";
PressBind(text);
}
void PressBind(string text)
{
Enum.TryParse(text, out Key key1);
Thread.Sleep(40);
label1.Text = "ready";
if (Keyboard.IsKeyDown(key1))
{
Thread.Sleep(40);
SendKeys.SendWait("e");
}
}
蝴蝶刀刀
相关分类