在c#中使用TweetSharp发布tweet需要花费很多时间

本文关键字:时间 tweet 发布 TweetSharp | 更新日期: 2023-09-27 18:18:38

我正在使用TweetSharp从我的c#应用程序发送推文。我的应用程序是一款基于XNA的游戏,在每场游戏结束时,分数会自动发送到Twitter账户。

这条推文每次都没有错误,但每次出现错误,游戏就会冻结1.5秒。

我像这样使用它来发布代码:

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

有什么办法可以缩短邮寄时间?

在c#中使用TweetSharp发布tweet需要花费很多时间

如果你使用。net 4.5在一个新线程中运行一些东西,你可以这样做

// 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 });
});