In my silverlight mvvm application i am using wcf service to fill listbox which is taking time to load so i need to use async and await in that. how can i use it in the bellow code.
my code in view model:
private void GetLanguage()
{
ServiceAgent.GetLanguage((s, e) =>Language = e.Result);
}
my code in service agent
public void GetLanguage(EventHandler<languageCompletedEventArgs> callback)
{
_Proxy.languageCompleted += callback;
_Proxy.languageAsync();
}
Can anyone help me
You must use TaskCompletionSource to convert EAP (event asynchronous model) to TAP (task asynchronous model). First, add new method to your ServiceAgent (you can create this even as an extension method):
TCS will create a task which you can await then. By using the existing model, it will bridge the gap and make it consumable with async/await. You can now consume it in the view model: