My requirement:
I have more than one company in my database, which individually has more than 100 email-ids(i.e, client email-ids).
For each company I am creating a new thread and writing email-ids in a log file.
But the problem is, all the values are not written in the text file. Some data are missing, why it is so?
Code:
====
private void Page_Load(object sender, System.EventArgs e)
{
for (i=1; i<=10000; i++)
{
arrText.Add("email_" + i + "@hotmail.com");
}
sLogFilePath = "C:\\Documents and Settings\\NSPL\\Desktop\\logfile.txt";
FileStream fsLogFile = new FileStream(sLogFilePath, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter swLogFile = new StreamWriter(fsLogFile);
swLogFile.BaseStream.Seek(0, SeekOrigin.End);
swLogFile.WriteLine("Log file starts here\n");
for (i=1; i<=3; i++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(InstanceMethod), i.ToString());
}
}
public void InstanceMethod(object CompanyID)
{
for (j=0; j<arrText.Count; j++)
{
swLogFile.WriteLine(CompanyID.ToString() + " " + arrText[j].ToString() + "\n");
}
swLogFile.Flush();
}
I have more than one company in my database, which individually has more than 100 email-ids(i.e, client email-ids).
For each company I am creating a new thread and writing email-ids in a log file.
But the problem is, all the values are not written in the text file. Some data are missing, why it is so?
Code:
====
private void Page_Load(object sender, System.EventArgs e)
{
for (i=1; i<=10000; i++)
{
arrText.Add("email_" + i + "@hotmail.com");
}
sLogFilePath = "C:\\Documents and Settings\\NSPL\\Desktop\\logfile.txt";
FileStream fsLogFile = new FileStream(sLogFilePath, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter swLogFile = new StreamWriter(fsLogFile);
swLogFile.BaseStream.Seek(0, SeekOrigin.End);
swLogFile.WriteLine("Log file starts here\n");
for (i=1; i<=3; i++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(InstanceMethod), i.ToString());
}
}
public void InstanceMethod(object CompanyID)
{
for (j=0; j<arrText.Count; j++)
{
swLogFile.WriteLine(CompanyID.ToString() + " " + arrText[j].ToString() + "\n");
}
swLogFile.Flush();
}