muralik Posted June 19, 2003 Posted June 19, 2003 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(); } Quote
Administrators PlausiblyDamp Posted June 19, 2003 Administrators Posted June 19, 2003 Are all these threads writing to the same log file at the same time? If so you could be experiencing locking problems. You might want to look at syncronising the threads or perhaps implement a single thread to do the file IO Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.