【问题标题】:Posting a tweet with TweetSharp in C# is taking much time在 C# 中使用 TweetSharp 发布推文需要很长时间
【发布时间】:2013-06-11 06:56:48
【问题描述】:

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

推文每次发布都没有错误,但每次发布时,游戏都会冻结大约 1.5 秒。

我正在使用它来发布代码:

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

有什么办法可以减少发布时间?

【问题讨论】:

  • 您可能无法加快速度,但您可以将其置于后台工作程序 (msdn.microsoft.com/en-us/library/…) 中,以便程序在执行时继续运行。
  • 感谢您的快速答复!我使用 XNA 的一个更简单的功能进行多线程处理,它就像一个魅力!

标签: c# .net twitter xna tweetsharp


【解决方案1】:

如果您使用 .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 });
});

【讨论】:

    猜你喜欢
    • 2012-11-27
    • 2010-11-15
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多