Почему не изменяется текст консоли - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace ConsoleApplication6
{
class Program
{
static Random rnd = new Random();
static int x=10;
static void Main(string[] args)
{
Timer a = new Timer(10000);
a.Elapsed += a_Elapsed;
a.Start();
do
{
switch (x)
{
case 1:
Console.BackgroundColor = ConsoleColor.Black;
break;
case 2: Console.BackgroundColor = ConsoleColor.Blue;
break;
case 3: Console.BackgroundColor = ConsoleColor.Cyan;
break;
case 4: Console.BackgroundColor = ConsoleColor.DarkBlue;
break;
case 5: Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case 6: Console.BackgroundColor = ConsoleColor.DarkGray;
break;
}
}
while (true);
}
static void a_Elapsed(object sender, ElapsedEventArgs e)
{
x = rnd.Next(1, 6);
}
}
}Решение задачи: «Почему не изменяется текст консоли»
textual
Листинг программы
static Random rnd = new Random();
static int x=10;
static void Main(string[] args)
{
Timer a = new Timer(10);
a.Elapsed += a_Elapsed;
a.Start();
do
{
switch (x)
{
case 1:
Console.BackgroundColor = ConsoleColor.Black;
break;
case 2: Console.BackgroundColor = ConsoleColor.Blue;
break;
case 3: Console.BackgroundColor = ConsoleColor.Cyan;
break;
case 4: Console.BackgroundColor = ConsoleColor.DarkBlue;
break;
case 5: Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case 6: Console.BackgroundColor = ConsoleColor.DarkGray;
break;
default:
break;
}
Console.ReadKey();
}
while (true);
}
static void a_Elapsed(object sender, ElapsedEventArgs e)
{
x = rnd.Next(1, 6);
}
}