TaskCompletionSource <tresult>始终为null </tresult>

时间:2014-01-20 00:50:24

标签: c# task-parallel-library

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?!

       }

这个问题背后的原因是什么?

0 个答案:

没有答案