Classe System::Threading::Timer

Timer class

Timer class that executes job item in separate thread after delay. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

class Timer : public System::Object

Méthodes

MéthodeDescription
Change(int64_t, int64_t)Replanifie ou annule la minuterie.
Change(System::TimeSpan, System::TimeSpan)Replanifie ou annule la minuterie.
Dispose()Annule la planification de la minuterie.
Timer(TimerCallback)Constructeur.
Timer(TimerCallback, const System::SharedPtr<System::Object>&, int64_t, int64_t)Constructeur.
Timer(TimerCallback, const System::SharedPtr<System::Object>&, System::TimeSpan, System::TimeSpan)Constructeur.

Remarques

#include "system/threading/thread.h"
#include "system/threading/timer.h"
#include "system/object.h"
#include "system/smart_ptr.h"
#include <iostream>

int main()
{
  using namespace System::Threading;

  auto number = 0;
  auto timer = System::MakeObject<Timer>([&number](System::SharedPtr<System::Object> object) -> void {
    std::cout << ++number << std::endl;
  }, nullptr, 0, 200);

  Thread::Sleep(1000);
  timer->Dispose();

  return 0;
}
/*
This code example produces the following output:
1
2
3
4
5
*/

Voir aussi