Task.Factory.StartNew没有启动?

时间:2013-05-09 18:30:36

标签: c# multithreading task-parallel-library

我正在尝试访问网关,获取数据然后返回UI线程。 ContinueWith运行,但Gateway永远不会运行??

ILogonResult result;

Task.Factory
.StartNew(() =>
    {
        result = Gateway.Authenticate(a, b);
    })
.ContinueWith(task =>
    {
        TaskScheduler.FromCurrentSynchronizationContext();
        DoSomeUI(result);
    }
);

1 个答案:

答案 0 :(得分:-1)

请注意,您似乎只是希望执行Gateway.Authenticate方法并将该结果类型返回给更新UI的方法。

Task.Factory
.StartNew(() =>
{
    return Gateway.Authenticate(a, b);
})
.ContinueWith((t) =>
{
    if (t.Exception == null)
    {
       DoSomeUI(t.Result);
    }else{
       //Handle Exception Message
    }
}
);
相关问题