5

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?

thegameg
  • 281
  • 4
  • 14
  • 1
    You probably can't speed it up, but you could put it in a background worker (http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker(v=vs.95).aspx) so that the program carries on whilst it is being executed. – razethestray Jun 14 '13 at 15:15
  • Thank you for the fast answer! I used an easier feature of XNA for multithreading and it works like a charm! – thegameg Jun 14 '13 at 16:54

1 Answers1

4

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 });
});
nityan
  • 316
  • 3
  • 11