Timer.Change 메서드

정의

타이머 시작 시간 및 메서드 호출 사이의 간격을 변경합니다.

오버로드

Change(Int32, Int32)

부호 있는 32비트 정수로 시간 간격을 측정하여 타이머 시작 시간 및 메서드 호출 사이의 간격을 변경합니다.

Change(Int64, Int64)

부호 있는 64비트 정수로 시간 간격을 측정하여 타이머 시작 시간 및 메서드 호출 사이의 간격을 변경합니다.

Change(TimeSpan, TimeSpan)

TimeSpan 값으로 시간 간격을 측정하여 타이머 시작 시간 및 메서드 호출 사이의 간격을 변경합니다.

Change(UInt32, UInt32)

부호 없는 32비트 정수로 시간 간격을 측정하여 타이머 시작 시간 및 메서드 호출 사이의 간격을 변경합니다.

Change(Int32, Int32)

Source:
Timer.cs
Source:
Timer.cs
Source:
Timer.cs

부호 있는 32비트 정수로 시간 간격을 측정하여 타이머 시작 시간 및 메서드 호출 사이의 간격을 변경합니다.

public:
 bool Change(int dueTime, int period);
public bool Change (int dueTime, int period);
member this.Change : int * int -> bool
Public Function Change (dueTime As Integer, period As Integer) As Boolean

매개 변수

dueTime
Int32

Timer가 구성될 때 지정되는 콜백 메서드를 호출하기 전의 지연 시간(밀리초)입니다. 타이머가 다시 시작되지 않도록 하려면 Infinite를 지정합니다. 타이머를 즉시 시작하려면 0을 지정합니다.

period
Int32

Timer가 생성되었을 때 지정된 콜백 메서드 호출 사이의 간격(밀리초)입니다. 정기적으로 신호를 보내지 않도록 하려면 Infinite를 지정합니다.

반환

타이머가 성공적으로 업데이트되었으면 true이고, 그렇지 않으면 false입니다.

예외

Timer가 이미 삭제된 경우

dueTime 또는 period 매개 변수가 음수이고 Infinite와 같지 않은 경우

예제

다음 코드 예제를 시작 Timer 하는 방법을 보여 줍니다는 및 호출의 집합된 수 후 해당 기간을 변경 합니다.

using namespace System;
using namespace System::Threading;

ref class StatusChecker
{
private:
    int invokeCount, maxCount;

public:
    StatusChecker(int count)
    {
        invokeCount  = 0;
        maxCount = count;
    }

    // This method is called by the timer delegate.
    void CheckStatus(Object^ stateInfo)
    {
        AutoResetEvent^ autoEvent = dynamic_cast<AutoResetEvent^>(stateInfo);
        Console::WriteLine("{0:h:mm:ss.fff} Checking status {1,2}.",
                           DateTime::Now, ++invokeCount);

        if (invokeCount == maxCount) {
            // Reset the counter and signal the waiting thread.
            invokeCount  = 0;
            autoEvent->Set();
        }
    }
};

ref class TimerExample
{
public:
    static void Main()
    {
        // Create an AutoResetEvent to signal the timeout threshold in the
        // timer callback has been reached.
        AutoResetEvent^ autoEvent = gcnew AutoResetEvent(false);

        StatusChecker^ statusChecker = gcnew StatusChecker(10);

        // Create a delegate that invokes methods for the timer.
        TimerCallback^ tcb =
           gcnew TimerCallback(statusChecker, &StatusChecker::CheckStatus);

        // Create a timer that invokes CheckStatus after one second, 
        // and every 1/4 second thereafter.
        Console::WriteLine("{0:h:mm:ss.fff} Creating timer.\n",
                           DateTime::Now);
        Timer^ stateTimer = gcnew Timer(tcb, autoEvent, 1000, 250);

        // When autoEvent signals, change the period to every half second.
        autoEvent->WaitOne(5000, false);
        stateTimer->Change(0, 500);
        Console::WriteLine("\nChanging period to .5 seconds.\n");

        // When autoEvent signals the second time, dispose of the timer.
        autoEvent->WaitOne(5000, false);
        stateTimer->~Timer();
        Console::WriteLine("\nDestroying timer.");
    }
};

int main()
{
    TimerExample::Main();
}
// The example displays output like the following:
//       11:59:54.202 Creating timer.
//       
//       11:59:55.217 Checking status  1.
//       11:59:55.466 Checking status  2.
//       11:59:55.716 Checking status  3.
//       11:59:55.968 Checking status  4.
//       11:59:56.218 Checking status  5.
//       11:59:56.470 Checking status  6.
//       11:59:56.722 Checking status  7.
//       11:59:56.972 Checking status  8.
//       11:59:57.223 Checking status  9.
//       11:59:57.473 Checking status 10.
//       
//       Changing period to .5 seconds.
//       
//       11:59:57.474 Checking status  1.
//       11:59:57.976 Checking status  2.
//       11:59:58.476 Checking status  3.
//       11:59:58.977 Checking status  4.
//       11:59:59.477 Checking status  5.
//       11:59:59.977 Checking status  6.
//       12:00:00.478 Checking status  7.
//       12:00:00.980 Checking status  8.
//       12:00:01.481 Checking status  9.
//       12:00:01.981 Checking status 10.
//       
//       Destroying timer.
using System;
using System.Threading;

class TimerExample
{
    static void Main()
    {
        // Create an AutoResetEvent to signal the timeout threshold in the
        // timer callback has been reached.
        var autoEvent = new AutoResetEvent(false);
        
        var statusChecker = new StatusChecker(10);

        // Create a timer that invokes CheckStatus after one second, 
        // and every 1/4 second thereafter.
        Console.WriteLine("{0:h:mm:ss.fff} Creating timer.\n", 
                          DateTime.Now);
        var stateTimer = new Timer(statusChecker.CheckStatus, 
                                   autoEvent, 1000, 250);

        // When autoEvent signals, change the period to every half second.
        autoEvent.WaitOne();
        stateTimer.Change(0, 500);
        Console.WriteLine("\nChanging period to .5 seconds.\n");

        // When autoEvent signals the second time, dispose of the timer.
        autoEvent.WaitOne();
        stateTimer.Dispose();
        Console.WriteLine("\nDestroying timer.");
    }
}

class StatusChecker
{
    private int invokeCount;
    private int  maxCount;

    public StatusChecker(int count)
    {
        invokeCount  = 0;
        maxCount = count;
    }

    // This method is called by the timer delegate.
    public void CheckStatus(Object stateInfo)
    {
        AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;
        Console.WriteLine("{0} Checking status {1,2}.", 
            DateTime.Now.ToString("h:mm:ss.fff"), 
            (++invokeCount).ToString());

        if(invokeCount == maxCount)
        {
            // Reset the counter and signal the waiting thread.
            invokeCount = 0;
            autoEvent.Set();
        }
    }
}
// The example displays output like the following:
//       11:59:54.202 Creating timer.
//       
//       11:59:55.217 Checking status  1.
//       11:59:55.466 Checking status  2.
//       11:59:55.716 Checking status  3.
//       11:59:55.968 Checking status  4.
//       11:59:56.218 Checking status  5.
//       11:59:56.470 Checking status  6.
//       11:59:56.722 Checking status  7.
//       11:59:56.972 Checking status  8.
//       11:59:57.223 Checking status  9.
//       11:59:57.473 Checking status 10.
//       
//       Changing period to .5 seconds.
//       
//       11:59:57.474 Checking status  1.
//       11:59:57.976 Checking status  2.
//       11:59:58.476 Checking status  3.
//       11:59:58.977 Checking status  4.
//       11:59:59.477 Checking status  5.
//       11:59:59.977 Checking status  6.
//       12:00:00.478 Checking status  7.
//       12:00:00.980 Checking status  8.
//       12:00:01.481 Checking status  9.
//       12:00:01.981 Checking status 10.
//       
//       Destroying timer.
Imports System.Threading

Public Module Example
    Public Sub Main()
        ' Use an AutoResetEvent to signal the timeout threshold in the
        ' timer callback has been reached.
        Dim autoEvent As New AutoResetEvent(False)

        Dim statusChecker As New StatusChecker(10)

        ' Create a timer that invokes CheckStatus after one second, 
        ' and every 1/4 second thereafter.
        Console.WriteLine("{0:h:mm:ss.fff} Creating timer." & vbCrLf, 
                          DateTime.Now)
        Dim stateTimer As New Timer(AddressOf statusChecker.CheckStatus, 
                                    autoEvent, 1000, 250)

        ' When autoEvent signals, change the period to every half second.
        autoEvent.WaitOne()
        stateTimer.Change(0, 500)
        Console.WriteLine(vbCrLf & "Changing period to .5 seconds." & vbCrLf)

        ' When autoEvent signals the second time, dispose of the timer.
        autoEvent.WaitOne()
        stateTimer.Dispose()
        Console.WriteLine(vbCrLf & "Destroying timer.")
    End Sub
End Module

Public Class StatusChecker
    Dim invokeCount, maxCount As Integer 

    Sub New(count As Integer)
        invokeCount  = 0
        maxCount = count
    End Sub

    ' The timer callback method.
    Sub CheckStatus(stateInfo As Object)
        Dim autoEvent As AutoResetEvent = DirectCast(stateInfo, AutoResetEvent)
        invokeCount += 1
        Console.WriteLine("{0:h:mm:ss.fff} Checking status {1,2}.", 
                          DateTime.Now, invokeCount)
        If invokeCount = maxCount Then
            ' Reset the counter and signal the waiting thread.
            invokeCount = 0
            autoEvent.Set()
        End If
    End Sub
End Class
' The example displays output like the following:
'       11:59:54.202 Creating timer.
'       
'       11:59:55.217 Checking status  1.
'       11:59:55.466 Checking status  2.
'       11:59:55.716 Checking status  3.
'       11:59:55.968 Checking status  4.
'       11:59:56.218 Checking status  5.
'       11:59:56.470 Checking status  6.
'       11:59:56.722 Checking status  7.
'       11:59:56.972 Checking status  8.
'       11:59:57.223 Checking status  9.
'       11:59:57.473 Checking status 10.
'       
'       Changing period to .5 seconds.
'       
'       11:59:57.474 Checking status  1.
'       11:59:57.976 Checking status  2.
'       11:59:58.476 Checking status  3.
'       11:59:58.977 Checking status  4.
'       11:59:59.477 Checking status  5.
'       11:59:59.977 Checking status  6.
'       12:00:00.478 Checking status  7.
'       12:00:00.980 Checking status  8.
'       12:00:01.481 Checking status  9.
'       12:00:01.981 Checking status 10.
'       
'       Destroying timer.

설명

콜백 메서드는 경과 후 dueTime 한 번 호출되고, 그 후에는 경과로 period 지정된 시간 간격이 경과할 때마다 호출됩니다.

가 0이면 dueTime 콜백 메서드가 즉시 호출됩니다. 이 이면 dueTime 콜백 메서드는 호출되지 않으며 타이머는 사용하지 않도록 설정되지만 에 대해 dueTime양수 값을 호출 Change 하고 지정하여 다시 사용하도록 설정할 수 Timeout.Infinite있습니다.

가 0 또는 Timeout.Infinite이고 dueTime 이 아닌 Timeout.Infinite경우 period 콜백 메서드는 한 번 호출되고 타이머의 주기적 동작은 사용하지 않도록 설정되지만 에 대해 period양수 값을 호출 Change 하고 지정하여 다시 사용하도록 설정할 수 있습니다.

메서드는 Change 대리자 TimerCallback 에서 호출할 수 있습니다.

추가 정보

적용 대상

Change(Int64, Int64)

Source:
Timer.cs
Source:
Timer.cs
Source:
Timer.cs

부호 있는 64비트 정수로 시간 간격을 측정하여 타이머 시작 시간 및 메서드 호출 사이의 간격을 변경합니다.

public:
 bool Change(long dueTime, long period);
public bool Change (long dueTime, long period);
member this.Change : int64 * int64 -> bool
Public Function Change (dueTime As Long, period As Long) As Boolean

매개 변수

dueTime
Int64

Timer가 구성될 때 지정되는 콜백 메서드를 호출하기 전의 지연 시간(밀리초)입니다. 타이머가 다시 시작되지 않도록 하려면 Infinite를 지정합니다. 타이머를 즉시 시작하려면 0을 지정합니다. 이 값은 4294967294보다 작거나 같아야 합니다.

period
Int64

Timer가 생성되었을 때 지정된 콜백 메서드 호출 사이의 간격(밀리초)입니다. 정기적으로 신호를 보내지 않도록 하려면 Infinite를 지정합니다.

반환

타이머가 성공적으로 업데이트되었으면 true이고, 그렇지 않으면 false입니다.

예외

Timer가 이미 삭제된 경우

dueTime 또는 period이 -1 미만입니다.

또는

dueTime 또는 period가 4294967294보다 큽니다.

설명

콜백 메서드는 경과 후 dueTime 한 번 호출되고, 그 후에는 경과로 period 지정된 시간 간격이 경과할 때마다 호출됩니다.

가 0이면 dueTime 콜백 메서드가 즉시 호출됩니다. 이 이면 dueTime 콜백 메서드는 호출되지 않으며 타이머는 사용하지 않도록 설정되지만 에 대해 dueTime양수 값을 호출 Change 하고 지정하여 다시 사용하도록 설정할 수 Timeout.Infinite있습니다.

가 0 또는 Timeout.Infinite이고 dueTime 이 아닌 Timeout.Infinite경우 period 콜백 메서드는 한 번 호출되고 타이머의 주기적 동작은 사용하지 않도록 설정되지만 에 대해 period양수 값을 호출 Change 하고 지정하여 다시 사용하도록 설정할 수 있습니다.

메서드는 Change 대리자 TimerCallback 에서 호출할 수 있습니다.

추가 정보

적용 대상

Change(TimeSpan, TimeSpan)

Source:
Timer.cs
Source:
Timer.cs
Source:
Timer.cs

TimeSpan 값으로 시간 간격을 측정하여 타이머 시작 시간 및 메서드 호출 사이의 간격을 변경합니다.

public:
 bool Change(TimeSpan dueTime, TimeSpan period);
public:
 virtual bool Change(TimeSpan dueTime, TimeSpan period);
public bool Change (TimeSpan dueTime, TimeSpan period);
member this.Change : TimeSpan * TimeSpan -> bool
abstract member Change : TimeSpan * TimeSpan -> bool
override this.Change : TimeSpan * TimeSpan -> bool
Public Function Change (dueTime As TimeSpan, period As TimeSpan) As Boolean

매개 변수

dueTime
TimeSpan

TimeSpan가 구성될 때 지정되는 콜백 메서드를 호출하기 전의 지연 시간을 나타내는 Timer입니다. 타이머가 다시 시작되지 않도록 하려면 InfiniteTimeSpan를 지정합니다. 타이머를 즉시 시작하려면 Zero를 지정합니다.

period
TimeSpan

Timer가 생성되었을 때 지정된 콜백 메서드 호출 사이의 간격입니다. 정기적으로 신호를 보내지 않도록 하려면 InfiniteTimeSpan를 지정합니다.

반환

타이머가 성공적으로 업데이트되었으면 true이고, 그렇지 않으면 false입니다.

구현

예외

Timer가 이미 삭제된 경우

dueTime 또는 period 매개 변수 값이 -1밀리초 미만인 경우

dueTime 또는 period 매개 변수 값이 4294967294밀리초보다 큰 경우

예제

다음 코드 예제를 시작 Timer 하는 방법을 보여 줍니다는 및 호출의 집합된 수 후 해당 기간을 변경 합니다.

using namespace System;
using namespace System::Threading;
ref class StatusChecker
{
private:
   int invokeCount;
   int maxCount;

public:
   StatusChecker( int count )
      : invokeCount( 0 ), maxCount( count )
   {}


   // This method is called by the timer delegate.
   void CheckStatus( Object^ stateInfo )
   {
      AutoResetEvent^ autoEvent = dynamic_cast<AutoResetEvent^>(stateInfo);
      Console::WriteLine( "{0} Checking status {1,2}.", DateTime::Now.ToString(  "h:mm:ss.fff" ), (++invokeCount).ToString() );
      if ( invokeCount == maxCount )
      {
         
         // Reset the counter and signal main.
         invokeCount = 0;
         autoEvent->Set();
      }
   }

};

int main()
{
   AutoResetEvent^ autoEvent = gcnew AutoResetEvent( false );
   StatusChecker^ statusChecker = gcnew StatusChecker( 10 );
   
   // Create the delegate that invokes methods for the timer.
   TimerCallback^ timerDelegate = gcnew TimerCallback( statusChecker, &StatusChecker::CheckStatus );
   TimeSpan delayTime = TimeSpan(0,0,1);
   TimeSpan intervalTime = TimeSpan(0,0,0,0,250);
   
   // Create a timer that signals the delegate to invoke CheckStatus 
   // after one second, and every 1/4 second thereafter.
   Console::WriteLine( "{0} Creating timer.\n", DateTime::Now.ToString(  "h:mm:ss.fff" ) );
   Timer^ stateTimer = gcnew Timer( timerDelegate,autoEvent,delayTime,intervalTime );
   
   // When autoEvent signals, change the period to every 1/2 second.
   autoEvent->WaitOne( 5000, false );
   stateTimer->Change( TimeSpan(0), intervalTime + intervalTime );
   Console::WriteLine( "\nChanging period.\n" );
   
   // When autoEvent signals the second time, dispose of the timer.
   autoEvent->WaitOne( 5000, false );
   stateTimer->~Timer();
   Console::WriteLine( "\nDestroying timer." );
}
using System;
using System.Threading;

class TimerExample
{
    static void Main()
    {
        AutoResetEvent autoEvent     = new AutoResetEvent(false);
        StatusChecker  statusChecker = new StatusChecker(10);

        // Create the delegate that invokes methods for the timer.
        TimerCallback timerDelegate = 
            new TimerCallback(statusChecker.CheckStatus);

        TimeSpan delayTime = new TimeSpan(0, 0, 1);
        TimeSpan intervalTime = new TimeSpan(0, 0, 0, 0, 250);

        // Create a timer that signals the delegate to invoke 
        // CheckStatus after one second, and every 1/4 second 
        // thereafter.
        Console.WriteLine("{0} Creating timer.\n", 
            DateTime.Now.ToString("h:mm:ss.fff"));
        Timer stateTimer = new Timer(
            timerDelegate, autoEvent, delayTime, intervalTime);

        // When autoEvent signals, change the period to every 
        // 1/2 second.
        autoEvent.WaitOne(5000, false);
        stateTimer.Change(new TimeSpan(0), 
            intervalTime + intervalTime);
        Console.WriteLine("\nChanging period.\n");

        // When autoEvent signals the second time, dispose of 
        // the timer.
        autoEvent.WaitOne(5000, false);
        stateTimer.Dispose();
        Console.WriteLine("\nDestroying timer.");
    }
}

class StatusChecker
{
    int invokeCount, maxCount;

    public StatusChecker(int count)
    {
        invokeCount  = 0;
        maxCount = count;
    }

    // This method is called by the timer delegate.
    public void CheckStatus(Object stateInfo)
    {
        AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;
        Console.WriteLine("{0} Checking status {1,2}.", 
            DateTime.Now.ToString("h:mm:ss.fff"), 
            (++invokeCount).ToString());

        if(invokeCount == maxCount)
        {
            // Reset the counter and signal Main.
            invokeCount  = 0;
            autoEvent.Set();
        }
    }
}
Imports System.Threading

Public Class TimerExample

    <MTAThread> _
    Shared Sub Main()
    
        Dim autoEvent As New AutoResetEvent(False)
        Dim statusChecker As New StatusChecker(10)

        ' Create the delegate that invokes methods for the timer.
        Dim timerDelegate As TimerCallback = _
            AddressOf statusChecker.CheckStatus

        Dim delayTime As New TimeSpan(0, 0, 1)
        Dim intervalTime As New TimeSpan(0, 0, 0, 0, 250)

        ' Create a timer that signals the delegate to invoke 
        ' CheckStatus after one second, and every 1/4 second 
        ' thereafter.
        Console.WriteLine("{0} Creating timer." & vbCrLf, _
            DateTime.Now.ToString("h:mm:ss.fff"))
        Dim stateTimer As Timer = New Timer( _
            timerDelegate, autoEvent, delayTime, intervalTime)

        ' When autoEvent signals, change the period to every 
        ' 1/2 second.
        autoEvent.WaitOne(5000, False)
        stateTimer.Change( _
            new TimeSpan(0), intervalTime.Add(intervalTime))
        Console.WriteLine(vbCrLf & "Changing period." & vbCrLf)

        ' When autoEvent signals the second time, dispose of 
        ' the timer.
        autoEvent.WaitOne(5000, False)
        stateTimer.Dispose()
        Console.WriteLine(vbCrLf & "Destroying timer.")
    
    End Sub
End Class

Public Class StatusChecker

    Dim invokeCount, maxCount As Integer 

    Sub New(count As Integer)
        invokeCount  = 0
        maxCount = count
    End Sub

    ' This method is called by the timer delegate.
    Sub CheckStatus(stateInfo As Object)
        Dim autoEvent As AutoResetEvent = _
            DirectCast(stateInfo, AutoResetEvent)
        invokeCount += 1
        Console.WriteLine("{0} Checking status {1,2}.", _
            DateTime.Now.ToString("h:mm:ss.fff"), _
            invokeCount.ToString())

        If invokeCount = maxCount Then
        
            ' Reset the counter and signal to stop the timer.
            invokeCount  = 0
            autoEvent.Set()
        End If
    End Sub

End Class

설명

콜백 메서드는 경과 후 dueTime 한 번 호출되고, 그 후에는 경과로 period 지정된 시간 간격이 경과할 때마다 호출됩니다.

가 이TimeSpan.ZerodueTime 콜백 메서드가 즉시 호출됩니다. 이 이면 dueTime 콜백 메서드는 호출되지 않으며 타이머는 사용하지 않도록 설정되지만 에 대해 dueTime양수 값을 호출 Change 하고 지정하여 다시 사용하도록 설정할 수 InfiniteTimeSpan있습니다.

가 또는 이고 dueTime 가 양수이면 period 콜백 메서드가 한 번 호출되고 타이머의 주기적 동작은 사용하지 않도록 설정되지만 에 대해 period0보다 큰 값을 호출 Change 하고 지정하여 다시 사용하도록 설정할 수 있습니다.InfiniteTimeSpanTimeSpan.Zero

메서드는 Change 대리자 TimerCallback 에서 호출할 수 있습니다.

추가 정보

적용 대상

Change(UInt32, UInt32)

Source:
Timer.cs
Source:
Timer.cs
Source:
Timer.cs

중요

이 API는 CLS 규격이 아닙니다.

부호 없는 32비트 정수로 시간 간격을 측정하여 타이머 시작 시간 및 메서드 호출 사이의 간격을 변경합니다.

public:
 bool Change(System::UInt32 dueTime, System::UInt32 period);
[System.CLSCompliant(false)]
public bool Change (uint dueTime, uint period);
[<System.CLSCompliant(false)>]
member this.Change : uint32 * uint32 -> bool
Public Function Change (dueTime As UInteger, period As UInteger) As Boolean

매개 변수

dueTime
UInt32

Timer가 구성될 때 지정되는 콜백 메서드를 호출하기 전의 지연 시간(밀리초)입니다. 타이머가 다시 시작되지 않도록 하려면 Infinite를 지정합니다. 타이머를 즉시 시작하려면 0을 지정합니다.

period
UInt32

Timer가 생성되었을 때 지정된 콜백 메서드 호출 사이의 간격(밀리초)입니다. 정기적으로 신호를 보내지 않도록 하려면 Infinite를 지정합니다.

반환

타이머가 성공적으로 업데이트되었으면 true이고, 그렇지 않으면 false입니다.

특성

예외

Timer가 이미 삭제된 경우

설명

콜백 메서드는 경과 후 dueTime 한 번 호출되고, 그 후에는 경과로 period 지정된 시간 간격이 경과할 때마다 호출됩니다.

가 0이면 dueTime 콜백 메서드가 즉시 호출됩니다. 이 이면 dueTime 콜백 메서드는 호출되지 않으며 타이머는 사용하지 않도록 설정되지만 에 대해 dueTime양수 값을 호출 Change 하고 지정하여 다시 사용하도록 설정할 수 Timeout.Infinite있습니다.

가 0 또는 Timeout.Infinite이고 dueTime 이 아닌 Timeout.Infinite경우 period 콜백 메서드는 한 번 호출되고 타이머의 주기적 동작은 사용하지 않도록 설정되지만 에 대해 period양수 값을 호출 Change 하고 지정하여 다시 사용하도록 설정할 수 있습니다.

메서드는 Change 대리자 TimerCallback 에서 호출할 수 있습니다.

추가 정보

적용 대상