1 回答

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊
問(wèn)題出在new Thread(()=> { ... });This is creating a new function 而不僅僅是新函數(shù)調(diào)用。正在創(chuàng)建的函數(shù)應(yīng)該像這樣移動(dòng)到一個(gè)單獨(dú)的函數(shù)中
private void ReadKey(){
// Waits for getInput.Set()
getInput.WaitOne();
//The problem with this is the read keys stacking up
// causing the need for a lot of keystrokes
input = Console.ReadKey().KeyChar;
gotInput.Set();
}
在班級(jí)里面。
做這些
AutoResetEvent getInput, gotInput;
char input;
類變量并在內(nèi)部初始化它們Setup(){...}
最后Thread tom = new Thread(ReadKey);在當(dāng)前正在制作新功能的地方調(diào)用。
注意:此答案不適用于最佳實(shí)踐,但會(huì)得到一個(gè)原型來(lái)工作。
- 1 回答
- 0 關(guān)注
- 121 瀏覽
添加回答
舉報(bào)