1

I have a problem with uploading videos using LinqToTwitter. I have a sample code, which works fine when it's called in a Console application, but hangs when it's used in a WebForms project.

private static ulong UploadMedia()
{
    const string path = "c:\\Temp\\video.mp4";
    var authorizer = new SingleUserAuthorizer
    {
        CredentialStore = new SingleUserInMemoryCredentialStore
        {
            ConsumerKey = "my_consumer_key",
            ConsumerSecret = "my_consumer_secret",
            AccessToken = "my_access_token",
            AccessTokenSecret = "my_access_token_secret"
        }
    };
    var tc = new TwitterContext(authorizer);
    var media = UploadMediaAsync(tc, File.ReadAllBytes(path)).Result;
    return media.MediaID;
}

private static async Task<Media> UploadMediaAsync(TwitterContext tc, byte[] media)
{
    return await tc.UploadMediaAsync(media, "video/mp4");
}

Anyone has an idea what goes wrong?

Peter Szekeli
  • 2,712
  • 3
  • 30
  • 44

1 Answers1

1

You're blocking the WebForms UI thread by calling .Result

See http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html to get an understanding of the issue and how to solve it.

sellotape
  • 8,034
  • 2
  • 26
  • 30