0
任何人都可以告訴我如何在異步wcf服務中使用'ManualResetEvent'嗎?我有一個控制檯應用程序,它調用異步wcf服務,並且我想在'oncomplete'事件結束後關閉控制檯應用程序。WCF異步 - 如何使用ManualResetEvent
如果可能請給我一個樣品。
在此先感謝。
任何人都可以告訴我如何在異步wcf服務中使用'ManualResetEvent'嗎?我有一個控制檯應用程序,它調用異步wcf服務,並且我想在'oncomplete'事件結束後關閉控制檯應用程序。WCF異步 - 如何使用ManualResetEvent
如果可能請給我一個樣品。
在此先感謝。
你會寫你的控制檯應用程序類似如下:
class Program
{
static ManualResetEvent exitEvent = new ManualResetEvent(false); // Create the wait handle
static void Main()
{
using(var client = CreateYourClient())
{
client.MethodCompleted += MethodCompleted;
client.MethodAsync(); // Start method
exitEvent.WaitOne(); // Block until the method is done...
}
}
static void MethodCompleted(object sender, MethodCompletedEventArgs args)
{
// Do your work...
// At this point, signal that the console can close...
exitEvent.Set();
}
}
不過,如果你只是做了一個方法調用的時候,它可能會更好,只是使它同步。如果你同時調用多個異步方法,這隻會是非常有益的。
謝謝里德。我會試一試,讓你知道。謝謝你的幫助。 – CoolArchTek