Saturday, September 1, 2007

[ C# ] Delegation and Aschronous method calling.

using System;
using System.Threading;

namespace OperationType
{
public delegate int AddtionSubtration( int a, int b );

public class Delegation
{
public Delegation()
{
this.DelegationChecker();
}
public bool DelegationChecker(){
Console.WriteLine("Scheduling Operation.\n--------------------");
AddtionSubtration addtionSubtration= new AddtionSubtration( this.Add );
Console.WriteLine( "Normal Operation," );
Console.WriteLine( " {0} ", addtionSubtration(2,3) );

binaryOperation= new AddtionSubtration( this.Add );
IAsyncResult iAsyncResult= addtionSubtration.BeginInvoke( 2, 3, null, null );
if( iAsyncResult.IsCompleted )
{
Console.WriteLine("Calling Aschronous ....");
Console.WriteLine("Aschronous {0}", addtionSubtration.EndInvoke( iAsyncResult ));
}
else{
Console.WriteLine("Thread is not on Schedule!!!");
System.Threading.WaitHandle waitHandle= iAsyncResult.AsyncWaitHandle;
if( waitHandle.WaitOne( 300, false ) )
if( iAsyncResult.IsCompleted )
Console.WriteLine("Ashchronous {0}", addtionSubtration.EndInvoke( iAsyncResult ) );
}
return true;
}
public int Add(int a, int b){
System.Threading.Thread.Sleep( 300 );
return (a+b);
}
public int Sub(int a, int b){
return (b-a);
}
}
}

Welcome message.

Hi, the age of this blog is about 10 minutes. So still this is under decoration. In couple of days time you can see more items.

Thnks for patience.
- under-the-hood.