Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In my current project I have had a recent issue and have trouble understanding it:

concurrency::create_task(BPClient->ReadAnswer()).then([this](Windows::Foundation::Collections::IVector<unsigned char>^ Vec) {
            WSS::InMemoryRandomAccessStream^ imras = ref new WSS::InMemoryRandomAccessStream();
            WSS::DataWriter^ dw = ref new WSS::DataWriter(imras->GetOutputStreamAt(0));
            for(long long i = 0; i < Vec->Size; i++){
                dw->WriteByte(Vec->GetAt(i));
            }
            concurrency::create_task(dw->StoreAsync()).then([this, imras](unsigned int Count){
                Windows::UI::Xaml::Media::Imaging::BitmapImage^ bi = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
                Image^ img = ref new Image();
                bi->SetSource(imras);
                img->Source = bi;
                img->Width = 400;
                img->Height = 400;
                img->SetValue(Grid::ColumnProperty, 2);
                concurrency::create_task(coredisp->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([=]() {
                    this->MainGrid->Children->Append(img);
                })));
            });
        });

This works fine and produces the expected result. But, if I change it to

concurrency::create_task(BPClient->ReadAnswer()).then([this](Windows::Foundation::Collections::IVector<unsigned char>^ Vec) {
            WSS::InMemoryRandomAccessStream^ imras = ref new WSS::InMemoryRandomAccessStream();
            WSS::DataWriter^ dw = ref new WSS::DataWriter(imras->GetOutputStreamAt(0));
            for(long long i = 0; i < Vec->Size; i++){
                dw->WriteByte(Vec->GetAt(i));
            }

            concurrency::create_task(dw->StoreAsync()).wait(); //consider this line
            Windows::UI::Xaml::Media::Imaging::BitmapImage^ bi = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
            Image^ img = ref new Image();
            bi->SetSource(imras);
            img->Source = bi;
            img->Width = 400;
            img->Height = 400;
            img->SetValue(Grid::ColumnProperty, 2);
            concurrency::create_task(coredisp->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([=]() {
                this->MainGrid->Children->Append(img);
            }))).wait();
        });

I eventually receive an error that an invalid parameter was passed to the last concurrency::create_task-call.

What is actually going on here? Is it not possible to mix concurrency::task::then and concurrency::task::wait? I think I am creating a similar task chain as when using concurrency::task::wait instead of concurrency::task::then.
Thank you

share|improve this question
 
Please post the exact error message you're getting. –  Yam Marcovic May 27 '13 at 20:54
add comment

1 Answer

In c++/cx that error is thrown when you wait on the UI thread, which you can't do. But if you're just appending to the xaml document you shouldn't have to wait.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.