locked
Tasks synchron

    Question

  • Hello,

    the following code to make a asynchron function synchron failed with an exception:

    auto x = create_task(doSomething());
    x.get(); // here an exception throws 
    x.wait();
    static task<void> doSomething()
    {
    	return create_task([=] 
    	{
    		OutputDebugString(L"doSomething");
    	});
    }

    there are something absent or is this way not allowed?

    Regards

    Urs


    u


    • Edited by urs32 Friday, November 16, 2012 10:50 PM
    Friday, November 16, 2012 10:49 PM

Answers

All replies

  • It would help if you would explain in which context this was called and what the exception was.

    Call task::wait on the UI thread is not allowed, so if this code is called on the UI thread an exception is expected.

    --Rob

    Friday, November 16, 2012 11:32 PM
    Owner
  • ok i found the Problem, it was in the UI SHCore Thread. I came from the filepicker...

    I did not understand the exception, it was a little bit confusing:

    An unhandled exception occurred during 0x5E2C9AD1 (msvcr110d.dll) in yyy.exe: An invalid parameter was passed to a function that classifies invalid parameters as serious.

    (Translated from german)

    Thanks



    u

    Saturday, November 17, 2012 12:12 AM
  • That is the error that is raised when task::wait is called on a UI thread.

    --Rob

    Saturday, November 17, 2012 12:18 AM
    Owner