Pages

Search

Monday, February 27, 2012

Starting a Process (application) sending arguments and reading the Output/Error



Any application like notepad or calculator or user applications (console or windows) can be invoked using “Process” class which falls in “System.Diagnostics” package or namespace.

Below code demonstrates, creating a console application “Divide2Numbers” which accepts 2 arguments and writes the division of the given numbers to console.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Divide2Numbers
{
    class Program
    {
        static void Main(string[] args)
        {
            //getting the input arguments and writing the result of the division
            double a = double.Parse(args[0]);
            double b = double.Parse(args[1]);
            Console.Write("Division of {0} and {1} is {2}", a, b, (a / b));
        }
    }
}


A windows application is created which has 2 textboxes to enter value for “a” and “b”.
User will enter the values and click on “Divide” button.

The .exe created from above console application is copied to the current windows application directory.

In the button “Divide” click event, application will create a process object which will invoke the above console application exe and sends the a, b arguments.

private void Divide_Click(object sender, EventArgs e)
        {
            try
            {
                //new process
                System.Diagnostics.Process p1 = new System.Diagnostics.Process();

                //sending the arguments (a,b) to divide application
                p1.StartInfo.Arguments = txtA.Text + " " + txtB.Text;

                //CreateNoWindow=false, to not open the process ui.
                p1.StartInfo.CreateNoWindow = false;

                //The application file path
                p1.StartInfo.FileName = Application.StartupPath + "/Divide2Numbers.exe";

                //UseShellExecute must be set to false, to redirect IO streams
                p1.StartInfo.UseShellExecute = false;

                //to redirect the error that occurs in the process
                p1.StartInfo.RedirectStandardError = true;

                //to redirect the output from the process
                p1.StartInfo.RedirectStandardOutput = true;

                //to start the process
                p1.Start();

                //reading the error and output from stream
                StreamReader oR = p1.StandardOutput;
                StreamReader eR = p1.StandardError;
                string strError = eR.ReadToEnd();
                string strOutput = oR.ReadToEnd();

                //displaying the error or result
                lblResult.Text = (strOutput.Trim().Length > 0) ? "Result : " + strOutput : "Error : " + strError;
            }
            catch (Exception exp)
            {
                MessageBox.Show("Error : " + exp.Message);
            }
        }

When user enters the value of a, b and click on “Divide” the application gets the result from console application through output stream.


Incase of Error, applications gets the error via Error Stream reader.


Friday, February 24, 2012

Custom Attributes


Custom attribute enables the capability of creating user defined attributes (types) extending “Attribute” class. Custom attribute helps to tag a property or class or method to identify the respective members at run time based on type.
Below Example helps to understand better.
In below example, the same business object can be used in 2 different entities to invoke actions specific to entity.
Class which has methods to read property values based on type.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace BusinessAttributes
{
    public class Attribute
    {
        //To read the value of a given property and type
        public object ReadPropertyValue(Object argBusinessObject, Type atrType)
        {
            Type objType = argBusinessObject.GetType();
            var properties = (from memInfo in objType.FindMembers(MemberTypes.Property, BindingFlags.Public | BindingFlags.Instance, null, null)
                              where memInfo.GetCustomAttributes(atrType, true).Count() > 0 &&
                              memInfo.GetCustomAttributes(atrType, true).All((o) =>
                              { if (o.ToString().Trim().ToUpper() == atrType.ToString().Trim().ToUpper()) { return true; } return false; })
                              select memInfo);
            if (properties.Count() == 0)
                throw new Exception("Business Property of type \"" + atrType.ToString() + "\" not found");
            if (properties.Count() > 1)
                throw new Exception("Business Property of type \"" + atrType.ToString() + "\"  found more than one");
            return objType.InvokeMember(properties.First().Name, BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public, null, argBusinessObject, null);

        }

        //To return custom attribute objects list
        public IList<Object> GetCustomAttribute(Object argBusinessObject, Type atrType)
        {
            Type objType = argBusinessObject.GetType();

            var properties = (from memInfo in objType.FindMembers(MemberTypes.Property, BindingFlags.Public | BindingFlags.Instance, null, null)
                              where memInfo.GetCustomAttributes(atrType, true).Count() > 0 &&
                              memInfo.GetCustomAttributes(atrType, true).All((o) =>
                              { if (o.ToString().Trim().ToUpper() == atrType.ToString().Trim().ToUpper()) { return true; } return false; })
                              select memInfo);
            if (properties.Count() == 0)
                throw new Exception("Business Property of type \"" + atrType.ToString() + "\" not found");
            if (properties.Count() > 1)
                throw new Exception("Business Property of type \"" + atrType.ToString() + "\"  found more than one");
            var customAttribute =
            (from att in properties.First().GetCustomAttributes(atrType, true)
             where att.GetType().ToString().Trim().ToUpper() == atrType.ToString().Trim().ToUpper()
             select att);
            return customAttribute.ToList();
        }
    }
}


Logger (Entity) class extending the BusinessAttributes.Attribute class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace DBLogger
{
    public class Logger : BusinessAttributes.Attribute
    {
        public Object LogObject
        {
            set;
            get;
        }
        //reading the employee details from object based on custom attribute type
        public string ReadDetails()
        {
            return "Log Information - " + ReadPropertyValue(LogObject, typeof(DBLogger.LogID)) + " - " + ReadPropertyValue(LogObject, typeof(DBLogger.LogDesc));
        }
    }
    public class LogID : Attribute { };
    public class LogDesc : Attribute { };
}


Employee  (Entity) class extending the BusinessAttributes.Attribute class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace EmployeeLib
{
    public class Employee : BusinessAttributes.Attribute
    {
        public Object EmployeeObject
        {
            set;
            get;
        }
        //reading the employee details from object based on custom attribute type
        public string ReadDetails()
        {
            IList<Object> dt = GetCustomAttribute(EmployeeObject, typeof(EmpID));
            EmpID objEmpID = dt[0] as EmpID;
            if (objEmpID.isActive)
                return "Employee Information (Active) - " + ReadPropertyValue(EmployeeObject, typeof(EmpID)) + " - " + ReadPropertyValue(EmployeeObject, typeof(EmpName));
            else
                return "Employee Information (Inactive) - " + ReadPropertyValue(EmployeeObject, typeof(EmpID)) + " - " + ReadPropertyValue(EmployeeObject, typeof(EmpName));
        }
    }

    public class EmpID : Attribute
    {
        public bool isActive { get; set; }

        public EmpID(bool blnActive)
        {
            isActive = blnActive;
        }
    };
    public class EmpName : Attribute
    { };
}

User Interface (Windows form)

//The common business object which can be used in 2 entities
        CommonBA objCommonBA = null;

        //when used clicks on "Log" button
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //creating an object for Log entity and setting the shared business object as Log Object
                DBLogger.Logger objLogger = new DBLogger.Logger() { LogObject = objCommonBA };
                //displaying the details of the log object
                MessageBox.Show(objLogger.ReadDetails());
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }

        //when used clicks on "Employee" button
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                //creating an object for Employee entity and setting the shared business object as Employee object
                EmployeeLib.Employee objEmp = new EmployeeLib.Employee() { EmployeeObject = objCommonBA };
                //displaying the employee details.
                MessageBox.Show(objEmp.ReadDetails());
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }

        //on form load
        private void Form1_Load(object sender, EventArgs e)
        {
            //creating the shared business object
            objCommonBA = new CommonBA() { ID = 1234, Desc = "srinivas" };
        }
    }

    //The Business class
    public class CommonBA
    {
        [DBLogger.LogID]
        [EmployeeLib.EmpID(true)]
        //ID attribute and tagged that this property can be used as Log ID in case of
        //log entity and the same as employee id in employee entity
        public int ID
        {
            get;
            set;
        }

        [DBLogger.LogDesc]
        [EmployeeLib.EmpName]
        //Desc attribute and tagged that this property can be used as Log Description in case of
        //log entity and the same as employee name in employee entity
        public string Desc
        {
            get;
            set;
        }
    }

Thursday, February 23, 2012

Linq and Extenstions Example

Linq helps to perform logical calculations with in memory by loading the object(s) at run time.
Just as like how we write sql queries in database to fetch the final list or table as required the similar can be achieved using linq. This also helps to reduce the lines of code (loc) to perform the calculations or logical relation of objects. For logically relation of objects before linq, developer has to create objects may be in a loop and add to collection etc…
Where as in case of linq, the same can be achieved with less number of locs. Also performing the logical relations or calculations with objects or arrays, etc.. using Linq are quite fater and gives better performance.

Regarding Extensions, .NET Framework has given an option for the developer to add extra methods to the framework. This methodology helps to improve the reusability across applications by just adding the extension reference. The methods that are added using extensions can be added to the class which is within the framework or can be added to the user defined class.
Ex:-
In my app I have a functionality to check if the given string in the UI is numeric, may be the same is required in other interfaces of my application.
“System.String” class has several methods, but has not method like “IsNumber()”.
So I will create an extension for “System.String” adding “IsNumber()” method.
I will put in the logic required and within my application across the modules I can just say like
txtName.Text.IsNumber() which returns Boolean to validate.


Below example illustrates an example to find the total salary paid to an employee between the given financial years.

Random objRand = null;

private void button1_Click(object sender, EventArgs e)

{

try

{

//collection for list of employees

List emps = new List();

//collection for list of salary for each employee

//yearly basis from 2011 to 2040

List empsals = new List();



objRand = new Random();

//Looping for 100 employees

for (int i = 1; i <= 100; i++)

{

//creating an employee object and adding to collection

//generating a random employee name of 10 characters in length

//random string is generated using extensions

emps.Add(new Employee() { ID = i, Name = objRand.NextString(10) });

for (int j = 2011; j < 2040; j++)

//creating sal object for each employee and for each year between 2011 and 2014

//sal is also random

empsals.Add(new EmployeeSal() { ID = i, Year = j, Sal = objRand.Next(10000, 50000) });

}

//trying to get the total salary paid to each employee between 2011 to 2040

var obj = (from emp1 in

(from emp in emps //inner join between employee and employee sal

from empsal in empsals

where

emp.ID == empsal.ID //join condition

select new { emp.Name, empsal.Sal }) //selecting the emp name and sal (one to many)

group emp1 by emp1.Name //grouping based on emp name

).ToDictionary(

l => l.Key, n => n.Sum((ss) => ss.Sal) //getting the emp name and
summing up the total sal paid
);
//obj is a dictionary, with key as employee name and value as total salary

}

catch (Exception exp)

{

MessageBox.Show("Error : " + exp.Message);

}

}

}


//random string extension method

public static class RandomExtensions

{

public static string NextString(this Random argRandom, int length)

{

//generating a random string of given lenght whose characters

//ascii code falls between 0 to 255

StringBuilder objString = new StringBuilder();

for (int l = 0; l < length; l++)

objString.Append((char)argRandom.Next(0, 255));

return objString.ToString();

}

}



//Employee and Employee Sal classes

public class Employee

{

public string Name;

public int ID;

}

public class EmployeeSal

{

public int ID;

public int Year;

public float Sal;

}

Wednesday, February 22, 2012

Invoking Member from a class using AssemblyQualifiedName

Generally, we invoke a instance method creating an object of the required class. In case of a static method, the method can be invoked using the class name.
Using “AssemblyQualifiedName”, it will be possible to invoke members of a class which belongs to given assembly name.
An assembly qualified name looks like
SubLib.Class1, SubLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Since, it is possible to invoke members of a class using its qualified name, it is much easier to add new business components to a system with the help of factory deisgn pattern and using the assembly qualified name.
Below example helps to understand invoking members from a class using qualified name.
Interface : MainLib.Int1
Class : MainLib.MessageInfo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MainLib
{
public interface Int1 : IDisposable
{
void Message();
void Message(MessageInfo argMessageInfo);
}
public class MessageInfo
{
public MessageInfo()
{
}
public string Message;
}
}

Class : Class1 implementing Int1
Class : Class3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MainLib;
using System.Windows.Forms;
using System.Collections;

namespace SubLib
{
public class Class1 : Int1
{
public Class1()
{
MessageBox.Show("Hi this is instance cons");
}

public Class1(MessageInfo argMessageInfo)
{
Message(argMessageInfo);
}

static Class1()
{
MessageBox.Show("Hi this is static cons");
}

public void Message()
{
MessageBox.Show("Hi This is class1");
}

public void Dispose()
{

}

public static void Msg()
{
MessageBox.Show("Hi this is static msg");
}
public void Message(MessageInfo argMessageInfo)
{
MessageBox.Show(argMessageInfo.Message);
}
}

public class Class3
{
public string str;
public string Mem1
{
get;
set;
}
private string Mem2
{
get;
set;
}

public void set_Mem1()
{
}
public Class3()
{
MessageBox.Show("Cons 1");
}
public Class3(int a)
{
MessageBox.Show("int Cons 1");
}
public Class3(string a)
{
MessageBox.Show("str Cons 1");
}
public Class3(MessageInfo oinfo)
{
MessageBox.Show("MessageInfo Cons 1");
}
}
}

Below code is to understand the invocations using Reflection assembly.

try
{
//SubLib.Class1 and MainLib.MessageInfo qualified names
string strClass1Type = "SubLib.Class1, SubLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
string strMessageInfoType = "MainLib.MessageInfo, MainLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";

//Getting the type based on qualified name
Type messageInfoType = Type.GetType(strMessageInfoType);

//Creating an instance or object for MessageInfo Class (calling its constructor)
MessageInfo obj = messageInfoType.InvokeMember(null, BindingFlags.CreateInstance, null, null, null) as MessageInfo;

//setting "Message" Property
messageInfoType.InvokeMember("Message", BindingFlags.Instance | BindingFlags.SetField | BindingFlags.Public, null, obj, new object[] { "Test Message" });

//Getting the type based on qualified name
Type classType = Type.GetType(strClass1Type);
//Calling the "Msg" static function from Class1
classType.InvokeMember("Msg", BindingFlags.InvokeMethod, null, null, null);

//Invoking the Class1 constructor
ConstructorInfo objINfo = classType.GetConstructor(System.Type.EmptyTypes);
Int1 objInt1 = objINfo.Invoke(null) as Int1;

//calling the "Message" function directly from the object
objInt1.Message();

//Invoking the "Message" function
classType.InvokeMember("Message", BindingFlags.InvokeMethod, null, objInt1, null);

//Invoking the Class1 Parameterised constructor
objINfo = classType.GetConstructor(new Type[] { obj.GetType() });
objInt1 = objINfo.Invoke(new object[] { obj }) as Int1;

//calling the "Message" function directly from the object
objInt1.Message();

//Creating an instance or object for Class1 Class (calling its constructor)
objInt1 = classType.InvokeMember(null, BindingFlags.CreateInstance, null, null, new object[] { obj }) as Int1;
objInt1.Message();


//Class3 qualified name
string strClass3Type = "SubLib.Class3, SubLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";

//getting the type
Type Class3Type = Type.GetType(strClass3Type);

//Creating an instance or object for Class3 Class (calling its constructor) and sending the message info object after setting the Message Property
object objClass3 = Class3Type.InvokeMember(null, BindingFlags.CreateInstance, null, null, new object[] { new MessageInfo() { Message = "hello" } });

//setting the "str" public variable
Class3Type.InvokeMember("str", BindingFlags.SetField, null, objClass3, new object[] { "hi srinivas" });

//setting the "Mem1" public property
Class3Type.InvokeMember("Mem1", BindingFlags.SetProperty, null, objClass3, new object[] { "hello" });

//setting the "Mem2" private property
Class3Type.InvokeMember("Mem2",
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.SetProperty, null, objClass3, new object[] { "hello private" });

}
catch (Exception exp)
{
MessageBox.Show(exp.Message, "Error");
}




Reference: http://msdn.microsoft.com/en-us/library/system.reflection.bindingflags.aspx

Monday, February 20, 2012

Cloning an Object

Cloning an object is not same as just like applying equal to operator.
Both the ways copy happens but it is differed like shallow copy and Deep copy.
Using equal to operator, a new reference will be created but the created reference still points the same object or memory block (reference pointers are also copied). This is called shallow copy.
Ex:-
Public class TestClass
{
int x;
}
TestClass obj1=new TestClass(){x=1};
TestClass obj2=obj1;
//Print(obj1.x)
//prints 1
//Print(obj2.x)
//prints 1

obj1.x=4 ;
//Print(obj1.x)
//prints 4
//Print(obj2.x)
//prints 4

Incase of Deep copy, the reference pointers are not expected to be copied instead will create a new memory block and copy the contents of the object.
The pointer of the new reference will point to the new object which is created.

To make the same above given example to do deep copy it can done either by making “TestClass” to implement “ICloneable” or like below.
Ex:-
Public class TestClass
{
int x;
}
TestClass obj1=new
TestClass(){x=1};
TestClass obj2=new TestClass(){x=obj1.x};
//Print(obj1.x)
//prints 1
//Print(obj2.x)
//prints 1

obj1.x=4 ;
//Print(obj1.x)
//prints 4
//Print(obj2.x)
//prints 1

Or by Implementing ICloneble

public class TestClass : ICloneable
{
int x;
public object Clone()
{
return new TestClass() { x = this.x };
}
}

Saturday, February 18, 2012

Tuesday, February 14, 2012

System.Threading - Classes Examples

System.Threading package has many classes which are to support thread synchronisation.
A class has to be choosed depending on situation, below source explains 7 situations.
AutoResetEvent, ManualResetEvent, Semaphore, Mutex, Monitor, ReadWriterLock, SpinWait

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static ManualResetEvent objManualResetEvent = null;
static AutoResetEvent objAutoResetEvent = null;
static System.Threading.Timer objTimer = null;

static void Main(string[] args)
{
try
{
//situation like hand shake, only when it is set once
//then the thread executes the block and resets
AutoReset();

//situation like flags, once after signal is given thread
//executes the block unless the signal is reset
ManualReset();

//Option to allow a more than a single thread (limit specified while creating semaphore object)
//to execute block of code
SemaphoreTrail();

//To allow only a single thread to execute a block of code
//another thread cannot execute the block until the current thread
//releases the mutex lock
//generally we use mutex to sync threads accross processes.
//It is heavy weight
MutexTrail();

//To allow only a single thread to execute a block of code
//also this helps to signalng a thread to execute the block by calling wait.
//calling wait will release lock and but will block current thread until it regains the lock.
// the locak can be regained only when the other thread(s) say pulse or pulseall
MonitorTrail();

//when a single write lock is acquired, all the readers will be in wait mode
//when there is one or more reader lock, writer lock wait till all the reader locks are releases.
//note timeouts are mandatory.
ReadWriterLockTrail();

//situations like where a thread has to wait till a funtion returns true, spinwait.spintuntil can be used
SpinUntilStart();
Console.ReadLine();
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
}


#region SpinUntil
static bool blnTest1 = false;
public static void SpinUntilStart()
{
Thread objTh = new Thread(SpinUntilTest);
objTh.Start();
Console.Read();
blnTest1 = true;
Console.ReadLine();
}

public static void SpinUntilTest()
{
Console.WriteLine("Thread started");
Console.WriteLine("Press enter to end thread");
SpinWait.SpinUntil(() => { return blnTest1; });
Console.WriteLine("Thread ended");
}

#endregion

#region ReadWriterLock
static string strFilepath = Application.StartupPath + "/temp.txt";
static ReaderWriterLock objReaderWriterLock = null;
public static void ReadWriterLockTrail()
{
if (File.Exists(strFilepath)) File.Delete(strFilepath);
objReaderWriterLock = new ReaderWriterLock();
for (int i = 0; i < 10; i++)
{
Thread objTh = new Thread(Writer);
objTh.Start();
Thread objTh1 = new Thread(Reader);
objTh1.Start();
}
}
public static void Reader()
{
try
{
objReaderWriterLock.AcquireReaderLock(1000000);
if (File.Exists(strFilepath))
{
Console.WriteLine(File.ReadAllText(strFilepath));
Thread.Sleep(500);
}
objReaderWriterLock.ReleaseReaderLock();
}
catch
{
Console.WriteLine("read lock failed");
return;
}
}
public static void Writer()
{
try
{
objReaderWriterLock.AcquireWriterLock(1000000);
File.AppendAllText(strFilepath, Environment.NewLine + "\n" + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss"));
Thread.Sleep(500);
objReaderWriterLock.ReleaseWriterLock();
}
catch
{
Console.WriteLine("write lock failed");
return;
}
}
#endregion

#region Monitor
static object Object_Monitor = new object();
public static void MonitorTrail()
{
for (int i = 0; i < 100; i++)
{
Thread objTh = new Thread(new ParameterizedThreadStart(mo_MonitorPrintMe));
objTh.Start(i);
}
}

public static void mo_MonitorPrintMe(object id)
{

Monitor.Enter(Object_Monitor);
Console.WriteLine(id);
Monitor.Pulse(Object_Monitor);
Monitor.Wait(Object_Monitor);

//Thread.Sleep(1000);
Console.WriteLine("Done - " + id);
Monitor.Exit(Object_Monitor);

}
#endregion

#region Mutex
static Mutex objMutex = null;

public static void MutexTrail()
{
objMutex = new Mutex(false, "Mut1");
for (int i = 0; i < 10; i++)
{
Thread objTh1 = new Thread(new ParameterizedThreadStart(mt_MutexPrintMe));
objTh1.Start(i);
}
}

public static void mt_MutexPrintMe(object id)
{
objMutex.WaitOne();
Console.WriteLine(id);
Thread.Sleep(500);
objMutex.ReleaseMutex();
}
#endregion

#region Semaphore
static Semaphore objSemaphore = null;
static int semmaxparallel = 10;
public static void SemaphoreTrail()
{
objSemaphore = new Semaphore(semmaxparallel, semmaxparallel, "Sem1");
for (int i = 0; i < semmaxparallel * 10; i++)
{
Thread objTh1 = new Thread(new ParameterizedThreadStart(st_SemPrintMe));
objTh1.Start(i);
}
}
static int semindex = 0;
public static void st_SemPrintMe(object id)
{
objSemaphore.WaitOne();
Console.WriteLine(id);
Interlocked.Increment(ref semindex);
if (Interlocked.CompareExchange(ref semindex, 0, semmaxparallel) == semmaxparallel)
{
Console.WriteLine("Semaphore is full.");
}
Thread.Sleep(2000);
objSemaphore.Release(1);
}
#endregion

#region auto reset
static void AutoReset()
{
objAutoResetEvent = new AutoResetEvent(false);
objTimer = new System.Threading.Timer(new TimerCallback(Timer_Callcack_AR), null, 0, 1000);
Thread objThread = new Thread(aUpdateTime);
objThread.Start();
}
public static void Timer_Callcack_AR(Object ar)
{
objAutoResetEvent.Set();
Console.WriteLine("done");
}
public static int acounter = 0;
public static void aUpdateTime()
{
while (true)
{
if (objAutoResetEvent.WaitOne())
{
acounter++;
Console.WriteLine(acounter);
}
}
}
#endregion

#region manual reset
static void ManualReset()
{
objManualResetEvent = new ManualResetEvent(false);
objTimer = new System.Threading.Timer(new TimerCallback(Timer_Callcack_MR), null, 0, 1000);
Thread objThread = new Thread(mUpdateTime);
objThread.Start();
}
public static void Timer_Callcack_MR(Object ar)
{
objManualResetEvent.Set();
Console.WriteLine("done");
}
public static int mcounter = 0;
public static void mUpdateTime()
{
while (true)
{
if (objManualResetEvent.WaitOne())
{
mcounter++;
Console.WriteLine(mcounter);
}
}
}
#endregion

}
}