0

When using LinqToTwitter the status update gets posted to twitter with no problems, however the route times out and when debugging the if statement after the await line the debugger never reaches that point. What can I do to fix this?

async public Task<object> Post(RetweetPost retweetInfo){

...


var auth = new SingleUserAuthorizer
{
  CredentialStore = new SingleUserInMemoryCredentialStore
  {
    ConsumerKey = "ConsumerKey",
    ConsumerSecret = "ConsumerSecret",
    AccessToken = account.OAuthToken,
    AccessTokenSecret = account.OAuthTokenSecret
  }
};

var twitterCtx = new TwitterContext(auth);

var tweet = await twitterCtx.TweetAsync(retweetInfo.tweet);

//DOES NOT REACH THIS LINE
if (tweet != null)
{
    return new RetweetPostResponse
    {
        twitterTweetId = tweet.StatusID.ToString()
    };
}
Piotr Tomasik
  • 9,074
  • 4
  • 44
  • 57
  • pls try putting a catch block and make sure no error is thrown . – Eldho Jul 30 '14 at 03:59
  • What does you mean by "never reached"? Does it hang? Does it continue to execute outside the method? Do you have "CLR Exceptions" enabled in the exception window in VS? – Yuval Itzchakov Jul 30 '14 at 04:45
  • If it truly hangs (with not error) there might be a bug in the client, and you should then look at this question: http://stackoverflow.com/q/21468137/885318 – i3arnon Jul 30 '14 at 06:41

2 Answers2

3

You probably have a call to Task<T>.Result or Task.Wait further up your call stack. This will cause a deadlock that I describe in detail on my blog.

await will capture a "context" by default (e.g., a UI context) and use that to resume the async method. When the TweetAsync task completes, it attempts to resume within that context (e.g., on the UI thread), but it can't because there's already a thread blocked in that context (i.e., calling Result/Wait).

The best solution is to replace all Result and Wait calls with await.

Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810
  • I normally don't like guessing answers this type of question is really just always due to the same issue. – usr Jul 30 '14 at 12:55
1

I believe the real problem I was facing was the ServiceStack Framework. As discussed here. Apparently async functions on routes were not supported until ServiceStack 4.

Community
  • 1
  • 1
Piotr Tomasik
  • 9,074
  • 4
  • 44
  • 57