Created
October 30, 2021 07:24
-
-
Save ValeryVerkhoturov/6dd630a0cf734f5e2a81c19f4c71e312 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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