Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int count = 10000,
- interval = 50,
- max = 200;
- string[] str =
- {
- "Заявка прошла ", "Заявка отклонена ", "Ставка повышена ", "Ставка понижена ",
- "Индекс понижен ", "Индекс повышен ", "Неизвестная ошибка ", "Заблокировано "
- };
- var rnd = new Random();
- var timer = new System.Timers.Timer() {Interval = interval, Enabled = true};
- int l = str.Length;
- var output = new StringBuilder();
- int i = 0, current = 0;
- timer.Elapsed += (sender, e) =>
- {
- Console.WriteLine(output);
- current = 0;
- output.Clear();
- };
- while (i < count)
- {
- if (current < max)
- {
- output.Append(str[rnd.Next(l)]);
- output.Append('\n');
- i++;
- current++;
- }
- }
- timer.Dispose();
- Console.ReadKey();
- (создаем таймер, который каждые 50 миллисекунд выполняет этот кусок кода:
- Код C#
- {
- if (i++ == count)
- (sender as IDisposable).Dispose();
- else
- Console.WriteLine(str[rnd.Next(str.Length)]);
- };)
- int count = 200,
- interval = 20;
- string[] str =
- {
- "Заявка прошла ", "Заявка отклонена ", "Ставка повышена ", "Ставка понижена ",
- "Индекс понижен ", "Индекс повышен ", "Неизвестная ошибка ", "Заблокировано "
- };
- var rnd = new Random();
- var timer = new Timer(interval);
- int i = 0;
- timer.Elapsed += (sender, e) =>
- {
- if (i++ == count)
- (sender as IDisposable).Dispose();
- else
- Console.WriteLine(str[rnd.Next(str.Length)]);
- };
- timer.Enabled = true;
- Console.ReadLine();
- Во втором случае выводим 200 сообщений, приостанавливая работу программы после каждого на 20 мс
- int count = 200,
- interval = 20;
- string[] str =
- {
- "Заявка прошла ", "Заявка отклонена ", "Ставка повышена ", "Ставка понижена ",
- "Индекс понижен ", "Индекс повышен ", "Неизвестная ошибка ", "Заблокировано "
- };
- var rnd = new Random();
- for (int i = 0; i < count; i++)
- {
- Console.WriteLine(str[rnd.Next(str.Length)]);
- Thread.Sleep(interval);
- }
- Console.ReadLine();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement