WCF Async - How to use ManualResetEvent

Can any one tell me how to use 'ManualResetEvent' in a async wcf service? I have a console application which makes calls to async wcf service and I wanted to close the console app after 'oncomplete' event finishes.

If possible please provide me a sample.

Thanks in advance.

Answers


You'd write your Console App something like the following:

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();
    }
}

However, if you're just doing a single method call, it's probably better to just make it synchronous. This would only really be beneficial if you're calling multiple asynchronous methods simultaneously.


Need Your Help

Will a system clock adjust affect running the stopwatch in C#?

c# .net multithreading real-time

Let's say I have Stopwatch running in my code and in the middle, some other application has changed the system clock (I have Domain Time on my server syncing every second).

Next Closest Pair Problem

math graph graph-theory

I'm sure most are familiar with the closest pair problem, but is there another alogrithm or a way to modify the current CP algorithm to get the next closest pair?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.