3
我有一個相當不錯的多線程的WinForms應用程序,採用的EventWaitHandle在一些地方同步訪問。如何檢測EventWaitHandle是否在等待?
所以我有類似下面的代碼:
List<int> _revTypes;
EventWaitHandle _ewh = new EventWaitHandle(false, EventResetMode.ManualReset);
void StartBackgroundTask() {
_ewh.Reset();
Thread t = new Thread(new ThreadStart(LoadStuff));
t.Start();
}
void LoadStuff() {
_revTypes = WebServiceCall.GetRevTypes()
// ...bunch of other calls fetching data from all over the place
// using the same pattern
_ewh.Set();
}
List<int> RevTypes {
get {
_ewh.WaitOne();
return _revTypes;
}
}
然後我打電話從UI .RevTypes
somewehre當LoadStuff
執行完畢,將返回的數據給我。
這一切完美的作品正確,但是RevTypes
只是一個屬性 - 居然有幾十這些。並且其中一個或幾個屬性以快速方式阻止用戶界面加載。
短期將基準代碼爲每個屬性的,有沒有辦法,看看哪些財產持有加載用戶界面?有沒有辦法查看EventWaitHandle是否被迫實際等待?