Closed romka2411 closed 9 years ago
The first example fails to compile with error C2440 because the Completed method does not return a value (hence void). Completed is a method on IAsyncOperation but you can just get a reference yourself as follows:
Windows::Foundation::IAsyncOperation<StorageFile> op = picker.PickSingleFileAsync();
op.Completed([](auto const & sender, AsyncStatus)
{
// ...
});
The second example fails with E_UNEXPECTED because you're calling ProcessEvents and that method has already been called from IFrameworkView::Run (inside sdk.extend.h). You can't just call it whenever you like. If you want to tweak message processing then you must also override the Run method.
Yes, right now there is only Modern::Exception. You can check the HRESULT for specifics.
(second question) just searched in google ways to wait windows runtime async function and found that.
As I understand, code under "try" must work same as task_ppl.wait().
Tried it in MainPage::OnNavigatedTo - it works. Tried it there - exceptions. It just an alternative to chains or await`s. I supposed that act inside CoreWindow class quite same like in MainPage.
I don’t know where you found that but its terrible advice. You should never poll completion with a loop. That’s just wasting CPU cycles. PPL’s task::wait blocks the calling thread until the task completes. If you want to run some code when the operation completes then stick the code inside the Completed lambda. That's what it’s for.
I tried create a chain based on your example:
there an error with casting variable 'a':Error C2440 'initializing': cannot convert from 'void' to 'Modern::Windows::Foundation::IAsyncOperationModern::Windows::Storage::StorageFile' App app.cpp 58
Also I tried await functions like advised on StackOverflow:
(placed like previous code in KeyUp function) the code under "try" throws E_UNEXPECTED. CoreWindow returned by "Windows::UI::Core::CoreWindow::GetForCurrentThread();" same as the "window.KeyUp([](CoreWindow const &cw, KeyEventArgs const & args)" (from KeyUp calling).
Am I wrong using this?
Also where exceptions from namespace Platform (like, AccessDeniedException, COMException etc)? Is there for now only one of them - base (Modern::Exception)?