locked
timer in winrt

    Question

  • Hi, i am trying to port some win32 code to winrt evironment. But i did not find timeSetEvent() and timeKillEvent in winrt.
    Is there any equivalent method to timeSetEvent() ?

    If not give some suggestion to do the same in winrt.  

    • Edited by AKEV Tuesday, August 21, 2012 11:35 AM
    Tuesday, August 21, 2012 11:33 AM

Answers

All replies

  • Instead of SetTimer(), you should use Windows::UI::Xaml::DispatcherTimer.  See the MSDN article here: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.dispatchertimer.aspx.

    • Marked as answer by AKEV Wednesday, August 22, 2012 5:47 AM
    Tuesday, August 21, 2012 2:35 PM
  • Could you please provide some sample code which demonstrate Windows::UI::Xaml::DispatcherTimer in c++

    Thanks in advance


    • Edited by AKEV Friday, August 24, 2012 11:04 AM
    Friday, August 24, 2012 11:03 AM
  • The link you provided is broken. Also, the page on MSDN for the DispatcherTimer does not have any C++ example code:

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.dispatchertimer

    Monday, September 10, 2012 6:52 PM
  • void MyClass::createAndRunTimer()
    {
      timer = ref new DispatcherTimer;
      timer->Tick += ref new EventHandler<Object^>(this, &MyClass::TimerTick);
    
      TimeSpan ts;
      ts.Duration = 10000 * TIMER_INTERVAL_IN_MS;
      timer->Interval = ts;
    
      timer->Start(); // to start timer
    }
    
    void MyClass::TimerTick(Object^ sender, Object^ e)
    {
      timer->Stop(); // to stop timer
    }
    

    Tuesday, September 11, 2012 8:30 AM
  • You can try by this         ThreadPoolTimer     class
    Tuesday, September 11, 2012 2:26 PM
  • Hi,

    I tried the above code but it is showing the following error.

    error C2664: 'Windows::Foundation::EventHandler<T>::EventHandler<MyClass*>(TFunctor,Platform::CallbackContext,bool)' : cannot convert parameter 2 from 'void (__cdecl TimerClass::*)(Platform::Object ^,Platform::Object ^) to 'Platform::CallbackContext'

    Wednesday, September 12, 2012 9:28 AM
  • You cannot vote on your own post Hi,

    Could you please provide some sample code which demonstrate Windows::System::Threading::ThreadPoolTimer in c++

    Thanks in advance

    Wednesday, September 12, 2012 10:01 AM
  • void MyClass::createAndRunTimer()
    {
      timer = ref new DispatcherTimer;
      timer->Tick += ref new EventHandler<Object^>(this, &MyClass::TimerTick);
    
      TimeSpan ts;
      ts.Duration = 10000 * TIMER_INTERVAL_IN_MS;
      timer->Interval = ts;
    
      timer->Start(); // to start timer
    }
    
    void MyClass::TimerTick(Object^ sender, Object^ e)
    {
      timer->Stop(); // to stop timer
    }


    I tried the above code but it is showing the following error.

    error C2664: 'Windows::Foundation::EventHandler<T>::EventHandler<MyClass*>(TFunctor,Platform::CallbackContext,bool)' : cannot convert parameter 2 from 'void (__cdecl TimerClass::*)(Platform::Object ^,Platform::Object ^) to 'Platform::CallbackContext'

    Wednesday, September 12, 2012 10:02 AM
  • when in need of sample code search the samples part of this site, you should always find a sample. here is one that covers this topic.

    http://code.msdn.microsoft.com/windowsapps/Pool-Sample-5aa60454/sourcecode?fileId=52285&pathId=45440281

    Saturday, September 15, 2012 4:47 AM