Reputation: 311
So i am a beginner programmer. I am in my second year of learning how to program.
So I am wondering if there is a easy way to wait for the Thread.Sleep to finish in c# console application. Because when i have a thread.sleep and a console.readkey behind that. The console.ReadKey will execute.
Could someone please explain to me how to do this. And why this is happening if you feel like it.
Upvotes: 2
Views: 910
Reputation: 311
Okay so this only happens when i used some other method.
if i were to do this
Thread.Sleep(); //sleep 100 seconds
Console.Read();
nothing happend when i pressed a button.
however using a diffrent method
static void Main(string[] args)
{
IntervalMessage("this is a test");
Console.ReadKey();
}
public static void IntervalMessage(string message)
{
for (int i = 0; i < message.Length; i++)
{
if (i == message.Length - 1)
{
Console.Write(message[i]);
System.Threading.Thread.Sleep(120);
}
else
{
Console.Write(message[i]);
System.Threading.Thread.Sleep(110);
}
}
Console.ResetColor();
}
it will be able to have take input while sleeping. Thanks for trying to help. figured it out myself.
Upvotes: 3