How to make an "old style" asynchronous method
If I have an asynchronous method with a callback
MyMethodAsync( <Input Parameters ...>, Callback);
how can i make it expected?
[This method is for a Windows 7 phone, but should be equally applicable to any similar C # design]
DNSEndpoint Endpoint = ...
NameResolutionCallback Callback = (nrr) => { ... }
DeviceNetworkInformation.ResolveHostNameAsync(Enpoint, Callback, null);
I want to put a waiting shell around this call, so I wait for the callback to complete before continuing with the next command.
You can use TaskCompletionSource:
var tcs = new TaskCompletionSource<TypeOfCallbackParameter>();
MyMethodAsync(..., r => tcs.SetResult(r));
return tcs.Task;