How to implement IAsyncOperationWithProgress

I am migrating some custom .NET threads to WINRT. Language is C #.

Is there an example implementation of IAsyncOperationWithProgress? Because the ReadAsync, WriteAsync methods from Windows.Storage.Streams require them. Custom implementation of WinRT streams is also welcome.

I found some C examples using create_async, but I want to do this in C # and I cannot find create_async in the Metro framework.

Thanks in advance

+6
source share
3 answers

For C #, you should check this // build a conversation on asynchronous programming .

If you use high-level C ++, you should see this article on how to do asynchronous operations in PPL.

If you need to implement your asynchronous operation from a low level of C ++, you should look at the WRL :: AsyncBase class .

-one
source

The following is an example of using IAsyncOperationWithProgress to display the installation process of an XAP file programmatically. I'm new to Win8 development, so I'm not sure if it is completely idiomatic.

Check out Dispatcher.BeginInvoke to marshal progress back into the UI thread. Hope this helps:

private async void InstallApp(string name, Uri uri) { try { StatusTextBlock.Text = "Installing app"; var installTask = InstallationManager.AddPackageAsync(name, uri); installTask.Progress = (installResult, progress) => Dispatcher.BeginInvoke(() => { StatusTextBlock.Text = "Progress: " + progress; }); var result = await installTask; StatusTextBlock.Text = "Done: " + result.InstallState.ToString(); } catch (Exception ex) { StatusTextBlock.Text = "Failed to install: " + ex.Message; } } 
+4
source

I hope they don’t vote for me, but here's how to do it in C ++

https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/concurrency#reporting-progress

0
source

All Articles