분당 한마디의 프로그램 (수업 시간)을 만들고 있는데, 내가 조사한 바에 따르면 은이어야합니다. 기본적으로 타이머가 10 초에 도달하면 스톱워치를 중지하고 (필요하지는 않지만) 사용자가 더 이상 입력하지 못하도록합니다. 나는 이것을 어떻게 얻을 수 있을까? 사용자가 Enter 키를 누르 때까지 그 프로그램에 컨트롤을 반환하지 않는일정 시간 동안 스톱워치를 중지하려면 어떻게합니까?
public void Timer30()
{
double userCharcount = 0;
string userType;
int timeInSeconds = 10;
//new instance of stopwatch
Stopwatch stopWatch = new Stopwatch();
//call level 1 words from wordbank
Console.WriteLine(WordBank.LevelOneWords);
stopWatch.Start();
//**this doesn't seem to work**
if (stopWatch.Elapsed.Seconds >= timeInSeconds)
{ Console.WriteLine("Time's up! Nice work.");
stopWatch.Stop();
Console.ReadKey();
}
userType = Console.ReadLine();
stopWatch.Stop();
//capture number of characters user types to calculate WPM
userCharcount = userType.Length;
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}" ,
ts.Hours , ts.Minutes , ts.Seconds ,
ts.Milliseconds/10);
Console.WriteLine("\nNice job! You finished in " + elapsedTime + "!");
Thread.Sleep(2000);
//CalculateWPMEasy(userCharCount);
}
전화하세요. 감사! –