简短的回答:你可以做,如果你是不是调度线程上,是这样的:
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。该页面上的体系结构也得到了很好的解释。