M
mahendranepali
I am making a simulator application that will simulate different
concurrent users connecting to a database. the application creates
different userkeys and pushes them to the database tables. The business
procedures hence interpret the userkey as a seperate request and act
accordingly. For this I need to check the response time to the DB for
say thousands of concurrent users. So what I did created Threads in a
Loop and each thread invoked the DAL Class to query the DB. I just had
to log the response (time to return dataset) of the DAL methods and log
them to a text file.
this is a sample code for multithreads writing to the file.
public class yyy
{
private Mutex mut = new Mutex();
public static void Main()
{
Thread t;
for(int i=1;i<=3;i++)
{
t = new Thread(new ThreadStart(new zzz().abc));
t.Start();
t.Join();
}
}
public void abc()
{
//Calls to DAL methods
this.WriteToFile();
}
private void WriteToFile()
{
mut.WaitOne();
using (StreamWriter sw = File.AppendText(@"d:\text.txt"))
try
{
sw.WriteLine(AppDomain.GetCurrentThreadId()) ;
sw.Flush();
sw.Close();
}
catch (Exception e)
{
Console.WriteLine("error:{0}", e);
}
finally
{
mut.ReleaseMutex();
}
}
}
The issue is that I have to use the Thread.Join() method else the main
terminates. Hence not all threads execute. But if I use Thread.Join()
then there are no concurrent users connecting. can anyone help me with
this.
Regards
Mickey
concurrent users connecting to a database. the application creates
different userkeys and pushes them to the database tables. The business
procedures hence interpret the userkey as a seperate request and act
accordingly. For this I need to check the response time to the DB for
say thousands of concurrent users. So what I did created Threads in a
Loop and each thread invoked the DAL Class to query the DB. I just had
to log the response (time to return dataset) of the DAL methods and log
them to a text file.
this is a sample code for multithreads writing to the file.
public class yyy
{
private Mutex mut = new Mutex();
public static void Main()
{
Thread t;
for(int i=1;i<=3;i++)
{
t = new Thread(new ThreadStart(new zzz().abc));
t.Start();
t.Join();
}
}
public void abc()
{
//Calls to DAL methods
this.WriteToFile();
}
private void WriteToFile()
{
mut.WaitOne();
using (StreamWriter sw = File.AppendText(@"d:\text.txt"))
try
{
sw.WriteLine(AppDomain.GetCurrentThreadId()) ;
sw.Flush();
sw.Close();
}
catch (Exception e)
{
Console.WriteLine("error:{0}", e);
}
finally
{
mut.ReleaseMutex();
}
}
}
The issue is that I have to use the Thread.Join() method else the main
terminates. Hence not all threads execute. But if I use Thread.Join()
then there are no concurrent users connecting. can anyone help me with
this.
Regards
Mickey