Skip to content

Instantly share code, notes, and snippets.

@clausjoergensen
Created June 4, 2012 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clausjoergensen/2871084 to your computer and use it in GitHub Desktop.
Save clausjoergensen/2871084 to your computer and use it in GitHub Desktop.
Method:
private Task<TextMessage> SendMessageToServiceAsync(TextMessage message)
{
var tcs = new TaskCompletionSource<TextMessage>();
SendMessageToService(message, (msg) => tcs.SetResult(msg));
return tcs.Task;
}
Calling it this way:
TextMessage sentMessage = await SendMessageToServiceAsync(message);
OnMessageSentAction(sentMessage);
Getting following error:
"The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'."
But marking the method with async, and doing 'await tcs.Task' doesn't work either. Same error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment