|
using System;
namespace Pvax.App.AsyncMethod
{
class MainClass
{
static void LingeringCallDone(IAsyncResult ar)
{
Fixture f = ar.AsyncState as Fixture;
double d = f.EndLingeringCall(ar);
Console.WriteLine(d);
}
static void RunSync()
{
Console.WriteLine("Synchronous call:");
Fixture f = new Fixture();
DateTime start = DateTime.Now;
double d = f.LingeringCall(0.0, 0.000000001, 2000000000);
DateTime stop = DateTime.Now;
Console.WriteLine(d);
Console.WriteLine(stop - start);
Console.WriteLine();
}
static void RunPoll()
{
Console.WriteLine("Asynchronous call with polling:");
Fixture f = new Fixture();
DateTime start = DateTime.Now;
IAsyncResult ar = f.BeginLingeringCall(0.0, 0.000000001, 2000000000, null, null);
Console.WriteLine("Calcualting in the background...");
double d = f.EndLingeringCall(ar);
DateTime stop = DateTime.Now;
Console.WriteLine(d);
Console.WriteLine(stop - start);
Console.WriteLine();
}
static void RunCallback()
{
Console.WriteLine("Asynchronous call with callback:");
double d;
Fixture f1 = new Fixture();
IAsyncResult ar1 = f1.BeginLingeringCall(0.0, 0.000000001, 2000000000, null, null);
Console.WriteLine("Computing...");
f1.BeginLingeringCall(10.0, 0.000000001, 1000000, new AsyncCallback(LingeringCallDone), f1);
d = f1.EndLingeringCall(ar1);
Console.WriteLine(d);
Console.WriteLine();
}
public static void Main(string[] args)
{
RunSync();
RunPoll();
RunCallback();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
I'm a system administrator from Moscow, Russia. Programming is one of my hobbies. I presume I'm one of the first Russians who created a Web site dedicated to .Net known that time as NGWS. However, the Web page has been abandoned a long ago.