locked
DelayTimer not working properly

    Question

  • Hey,

    I have the following function for an delayed event.

    For some reason the function is not working for numbers smaller than 21 :/ and I have no idea why.
    I also deleted all the files in the project and did a rebuild so somewhere in there must be an mistake

    Thx for the help in advance 

    void PowerNapper::MainPage::DelayTimer(int min){ int millisecond = min * 60000; timeLeft->Text="Some text for the gui"; auto timerDelegate = [this](Windows::System::Threading::ThreadPoolTimer^ timer) { auto uiDelegate = [this]() { //This part gets done when the delay Timer is over myMediaElement->Play(); timeLeft->Text=""; }; Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler(uiDelegate)); }; Windows::Foundation::TimeSpan delay = SDKSample::ThreadPool::ThreadPoolSample::MillisecondsToTimeSpan(millisecond); SDKSample::ThreadPool::DelayTimer = Windows::System::Threading::ThreadPoolTimer::CreateTimer(ref new Windows::System::Threading::TimerElapsedHandler(timerDelegate), delay); }

    Windows::Foundation::TimeSpan ThreadPoolSample::MillisecondsToTimeSpan(long milliseconds)
    {
    Windows::Foundation::TimeSpan time;
    time.Duration = milliseconds * 10000;
    return time;
    }



    • Edited by Pascal90909 Saturday, May 11, 2013 11:54 PM
    Saturday, May 11, 2013 8:39 PM

Answers

All replies

  • Sunday, May 12, 2013 2:32 PM
  • I did not get the function running it says incomplete type is not allowed, I also get the same massage if I write a number directly into the function. 

    	unsigned int millisecond = min * 60000;
    	void __cdecl wait(millisecond);

    Only this is compiling, but also not working properly, the gui remains responsive but the rest of the Button_Click part never gets executed

    	void __cdecl wait(  unsigned int _Milliseconds = 100);

    This is how I am starting the DelayTimer

    void PowerNapper::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    	DelayTimer(20);
    	B20min->Visibility = Windows::UI::Xaml::Visibility::Collapsed; 
    	B25min->Visibility = Windows::UI::Xaml::Visibility::Collapsed; 
    	B30min->Visibility = Windows::UI::Xaml::Visibility::Collapsed; 
    	CancelAlarm->Visibility = Windows::UI::Xaml::Visibility::Visible; 
    
    }
    If I can get It to work this way somehow I would be happy to, but it would be still interesting for what reason the Delay via threads is not working for numbers smaller than 21 

    Sunday, May 12, 2013 10:05 PM
  • Hi,

    I think maybe the time is too short for media element to play again. To provide this, we can changed textblock text instead of media element.

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 14, 2013 3:08 AM
  • It was an overflow problem
    • Marked as answer by Pascal90909 Tuesday, May 14, 2013 6:12 PM
    Tuesday, May 14, 2013 6:12 PM