簡短的回答:你可以做,如果你是不是調度線程上,是這樣的:
System.Threading.ThreadPool.QueueUserWorkItem(state =>
{
IAsyncResult asyncResult = svc.BeginSomething(null, null);
if (!asyncResult.CompletedSynchronously)
{
asyncResult.AsyncWaitHandle.WaitOne();
}
try
{
svc.EndSomething(asyncResult);
}
catch
{
throw;
}
finally
{
asyncResult.AsyncWaitHandle.Close();
}
});
這樣做的最大的好處是,你可以保持您的域模型層同步像過去,你可以很容易地實現等懶加載...
但在實踐中你只能使用它時,你設計你的應用程序要嚴格遵守MVVM/指揮模式,在那裏你r ViewModels和Commands處理調度程序線程和模型線程之間的切換。這需要做大量的地面工作,並且有一些陷阱,但是當它工作時,它的工作非常好。
如果您想要使用類似工作的即用型框架,可在此處獲得:CodeProject: Introducing the Model Thread View Thread Pattern。該頁面上的體系結構也得到了很好的解釋。