using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Timers;
namespace ConsoleApplication2
{
class MyThread
{
Thread tr;
string fileName;
string stroke;
public int count;
public MyThread(string fileName, string stroke, int count)
{
this.fileName = fileName;
this.stroke = stroke;
this.count = count;
tr = new Thread(this.Writing);
tr.Start();
tr.Join();// ожидание завершения потока
}
private void Writing()
{
FileStream aFile = new FileStream(fileName, FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(aFile);
aFile.Seek(0, SeekOrigin.End);
for (int i = 0; i < count; i++)
{
DateTime dt = DateTime.Now;
sw.WriteLine(stroke + dt.Hour + ":" + dt.Minute + ":" + dt.Second + ":" + dt.Millisecond);
Console.WriteLine(stroke + dt.Hour + ":" + dt.Minute + ":" + dt.Second + ":" + dt.Millisecond);
}
sw.Close();
}
}
class Program
{
static void Main(string[] args)
{
MyThread mtr1 = new MyThread(@"D:\log1.txt", "Srtoke #1 ", 10);
MyThread mtr2 = new MyThread(@"D:\log1.txt", "Srtoke #2 ", 10);
}
}
} |