win8学习--------计时器

//计时器1---ThreadPoolTimer
auto timerDelegate = [this](Windows::System::Threading::ThreadPoolTimer^ timer){
          auto uiDelegate = [this]()
        {
           
           //设置时间到了所要做的事情
        };

        Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal,
                             ref new Windows::UI::Core::DispatchedHandler(uiDelegate));
        };
     
     auto time = safe_cast<Platform::String^>("2000");//设置时间间隔
     int DelayTimerMilliseconds = _wtol(time->Data());
     Windows::Foundation::TimeSpan delay = MillisecondsToTimeSpan(DelayTimerMilliseconds);
     Windows::System::Threading::ThreadPoolTimer^DelayTimer = Windows::System::Threading::ThreadPoolTimer::CreateTimer(ref newWindows::System::Threading::TimerElapsedHandler(timerDelegate), delay);
计时器2----tick

if (m_timer==nullptr)
    {
    DispatcherTimer^    m_timer = ref new DispatcherTimer();
        m_timer->Tick += ref new Windows::Foundation::EventHandler<Platform::Object^>(this, &ReadPage::DispatcherTimer_Tick);
        TimeSpan ts;
        ts.Duration=1*10000;//0.0001s
    m_timer->Interval = ts;
        m_timer->Start();
    }
    else
    {
        m_timer->Start();
    }

void  ReadPage::DispatcherTimer_Tick(Platform::Object^ sender, Platform::Object^ e)
{
//在时间内做的事
}

 


posted @ 2012-08-21 15:14  win_and_first  阅读(718)  评论(0编辑  收藏  举报