public class MyEventTest {
private TaskCompletionSource<MyResultObj> _tcs
= new TaskCompletionSource();
// somewhere else...
myEventObj.MyEvent += (sender, args) => {
_tcs.SetResult(args);
}
// somewhere else...
Task.Factory.StartNew(() => {
MyResultObj obj = _tcs.Task.Result; // should wait until result is set
obj.ToString() // BOOM! Task is completed, but result is null?!
}
这个问题背后的原因是什么?