-2
private bool getWindowBool() {
bool myBool;
this.Invoke(new MethodInvoker(() => myBool = IsForegroundWindow));
return myBool;
}
爲什麼不能正常工作?我將如何做我想達到的目標?需要設置bool與交叉線程
private bool getWindowBool() {
bool myBool;
this.Invoke(new MethodInvoker(() => myBool = IsForegroundWindow));
return myBool;
}
爲什麼不能正常工作?我將如何做我想達到的目標?需要設置bool與交叉線程
明確的分配。編譯器不知道Invoke在這裏意味着什麼,並且它不會理解委託在方法結束之前被調用 - 所以它不能證明(在受限處理的情況下)它在返回之前被分配。更改爲:
bool myBool = false;
你會得到什麼錯誤? – JMK