Hi,
I am just trying to work on with mutex in Threading. I tried a sample application, could you please let me know whether this is the right way of doing a Mutex program.
Another doubt is that whether is it possible to return a value using a method which is called by a thread. In the above case changing
public void CalculateBalanc e() to
public int CalculateBalanc e(int prevamt,int amtdeposit) and return that value to the main method??
I am just trying to work on with mutex in Threading. I tried a sample application, could you please let me know whether this is the right way of doing a Mutex program.
Code:
static void Main(string[] args)
{
ThreadSample5_Muthex1 tt5_1 = new ThreadSample5_Muthex1();
Thread t5_One = new Thread(tt5_1.CalculateBalance);
tt5_1.CalculateBalance();
t5_One.Name = "ThreadTest";
t5_One.Start();
Console.ReadLine();
}
class ThreadSample5_Muthex1
{
int amtdeposited = 0;
public static Mutex mutex1 = new Mutex(false, "TestMutex");
public void CalculateBalance()
{
int PrevAmt = 100;
for (int j = 0; j <= 250; j++)
{
mutex1.WaitOne();
amtdeposited = amtdeposited + j;
}
mutex1.ReleaseMutex();
Console.WriteLine(amtdeposited + PrevAmt);
}
}
public void CalculateBalanc e() to
public int CalculateBalanc e(int prevamt,int amtdeposit) and return that value to the main method??
Comment