2010-12-28 3 views
3

내가 1000 초 간격으로 System.Windows.Forms.Timer을 가지고 있다고 상상해보십시오.System.Windows.Forms.Timer 클래스에서 Start()를 두 번 호출하면 어떻게됩니까?

Timer.Start() 메서드를 호출하고 500ms 후에 다시 Timer.Start()을 호출하면 어떻게됩니까? 두 번째 Start 통화는 간격을 재설정할지 여부를 결정합니다. 부작용이 있습니까?

+3

글쎄, 시도해보고 어떻게 될지 알아보십시오. –

답변

8

타이머가 이미 시작되었으므로 두 번째 호출이 영향을주지 않습니다.

관계없이이 값은 입니다.

+0

부작용이 있습니까? – Drake

+1

굵은 글씨로 "easy"를 넣을 수 있습니다. –

+0

@Drake - 등? 'Start'를 호출하는 것은'Enabled'를'true'로 설정하는 것과 같습니다. – Oded

2

Start()는 Enabled 속성을 true로 설정합니다. Enabled 속성이 이미 true로 설정된 경우 Enabled를 true로 다시 설정하고 계속 진행합니다.

마찬가지로 Stop()은 Enabled를 false로 설정합니다. 유 시작하면 아무 영향을 미치지 않습니다 두 번째 시작을 반환 입력하면 그것은 아무 영향을받지 않습니다

2

...

이 코드

class TimerTest 
{ 
    static int i = 0; 
    static void Tick(object sender, EventArgs e) 
    { 

     Console.WriteLine(i); 
     i++; 
    } 
    static void Main() 
    { 
     // interval = 500ms 
     Timer tmr = new Timer(); 
     tmr.Interval = 500; 
     tmr.Elapsed += Tick; 
     tmr.Start(); 
     Console.ReadLine(); 
     tmr.Start(); 
     Console.ReadLine(); 
     tmr.Stop(); 
     Console.ReadLine(); 
     tmr.Start(); 
     Console.ReadLine(); 
     tmr.Dispose(); // This both stops the timer and cleans up. 
    } 
} 

를 참조하십시오.

관련 문제