Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting a tweet with TweetSharp in C# is taking much time

I'm using TweetSharp to send tweets from my C# application. My application is a game based on XNA and at the end of each game the scores are automatically sent to a Twitter account.

The tweet is posted every single time with no errors, but every time it does that, the game freezes for like 1.5 seconds.

I'm using it like this to post the code :

twitterService.SendTweet(new SendTweetOptions { Status = status });

What could be the solution to reduce that posting time?

like image 558
thegameg Avatar asked Oct 03 '22 20:10

thegameg


1 Answers

If you are using .NET 4.5 to run something in a new thread you do this

// this is a better way to run something in the background
// this queues up a task on a background threadpool
await Task.Run(() => {
    twitterService.SendTweet(new SendTweetOptions { Status = status });
});

// this method of running a task in the background creates unnecessary overhead
Task.Factory.StartNew(() => {
    twitterService.SendTweet(new SendTweetOptions { Status = status });
});
like image 81
nityan Avatar answered Oct 10 '22 11:10

nityan