在同步模型中,它很简单
using (MyServiceClient msc = new MyServiceClient())
{
msc.Method();
}
但是如果我必须等到这个方法结束,然后做一些事情,它就行不通
private void EventHandler<MethodCompletedEventArgs> myEventHandler = new EventHandler<MethodCompletedEventArgs>(methodBody);
using (MyServiceClient msc = new MyServiceClient())
{
msc.MethdCompleted += myEventHandler;
msc.BeginMethod();
}
private void MethodBody()
{
//exception: client state is aborted
}
using
另外如何在语句中调用异步方法?