Reputation: 17527
If I want to expose this method from a UWP class library
public async Task<int> PlaySound(SoundGroup soundGroup, int index, Duration duration)
then I need to create a wrapper thus
public IAsyncOperation<int> PlaySoundAsync(SoundGroup soundGroup, int index, Duration duration)
{
return PlaySound(soundGroup, index, duration).AsAsyncOperation();
}
But the same trick fails with this method
public async Task PreLoadSoundPlayers()
because this
public IAsyncOperation PreLoadSoundPlayersAsync()
{
return PreLoadSoundPlayers().AsAsyncOperation();
}
gives the error
'Task' does not contain a definition for 'AsAsyncOperation' and no extension method 'AsAsyncOperation' accepting a first argument of type 'Task' could be found
What is the correct pattern for exposing asynchronous methods that do not have a data return type in a UWP class library?
Upvotes: 1
Views: 679
Reputation: 17527
Found it - I needed to use actions instead of operations.
public IAsyncAction PreLoadSoundPlayersAsync()
{
return PreLoadSoundPlayers().AsAsyncAction();
}
Upvotes: 2