Skip to content

Instantly share code, notes, and snippets.

@ValeryVerkhoturov
Created October 30, 2021 07:24
Show Gist options
  • Save ValeryVerkhoturov/6dd630a0cf734f5e2a81c19f4c71e312 to your computer and use it in GitHub Desktop.
Save ValeryVerkhoturov/6dd630a0cf734f5e2a81c19f4c71e312 to your computer and use it in GitHub Desktop.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
int countThreads = 10;
int sleepTime = 1000;
for (int i = 0; i < countThreads; i++)
{
Thread thread = new Thread(setDataInTextFileLine);
thread.Name = i.ToString();
thread.Start();
Thread.Sleep(sleepTime / countThreads);
}
}
private void setDataInTextFileLine()
{
int sleepTime = 1000;
for (int i = 0; i < 10000; i++)
{
using (StreamWriter streamWriter = new StreamWriter("text1.txt", true))
{
streamWriter.WriteLine(Thread.CurrentThread.Name + ":" + i.ToString());
}
Thread.Sleep(sleepTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment