Take the 2-minute tour ×

I am porting a .Net library that makes heavy use of the Asynchronous Programming Model(APM) to a Windows store app library.

I would like to keep the Method definitions the same so other code making use of the library will just work with the Windows store app version. (i.e. as much as I prefer it, no async await pattern).

Problem is though Windows store apps seem compatible with the APM the concrete AsyncResult class is missing. As a result one cannot get the delegate instance that BeginInvoke() was called on in the callback and call EndInvoke():

public MyObject EndDoSomething (IAsyncResult result)
    // Retrieve the delegate.
    AsyncResult asyncResult = (AsyncResult)result; // Not possible in Windows store app - no AsyncResult

    // Wait for the WaitHandle to become signaled.

    // Call EndInvoke to retrieve the results.
    MyObject rv = ((MyAsynchronousDelegate)asyncResult.AsyncDelegate).EndInvoke(result);

    // Close the wait handel
    result.AsyncWaitHandle.Close()  // Close() is also missing

    return rv;

So what is one to do?

share|improve this question
If you're going to create a library for Windows Store apps why would you want to impose the horror of the APM model on them, rather than exposing a TAP-based solution? Bear in mind that the rest of an application using your library would have to be modified to use the newer-style asynchrony anyway, so I don't think you're really saving anyone much trouble - and you're making it much more painful for new applications who want to use your library. –  Jon Skeet Jan 19 '13 at 10:49
Good point, because there is such a large number of apps using the library already compared to new apps that will target Windows store apps, even new apps tend to target the traditional .Net framework. Perhaps I might force their hand anyway... –  markmnl Jan 19 '13 at 11:02
You're specifically porting it for Windows Store apps though. Any new apps which aren't targeting Windows Store presumably would use the original library anyway. So think about what a Windows Store app developer would want to use. –  Jon Skeet Jan 19 '13 at 11:32
@user1896654: There is a NuGet library that brings async support to .NET 4.0 and other platforms. It's in beta, but it is an option. –  Stephen Cleary Jan 19 '13 at 11:55

Your Answer



Browse other questions tagged or ask your own question.