Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何保持流媒体连续-Tweetinvi_C#_Twitter Streaming Api_Tweetinvi - Fatal编程技术网

C# 如何保持流媒体连续-Tweetinvi

C# 如何保持流媒体连续-Tweetinvi,c#,twitter-streaming-api,tweetinvi,C#,Twitter Streaming Api,Tweetinvi,我从网上找到的代码中改编了以下代码。工作正常,但不连续运行并拉入新tweet。我需要改变什么?谢谢你的帮助 private static void Stream_FilteredStreamExample() { SqlConnection conn = new SqlConnection(@"Data Source=********************"); conn.Open(); for (; ; ) { try {

我从网上找到的代码中改编了以下代码。工作正常,但不连续运行并拉入新tweet。我需要改变什么?谢谢你的帮助

private static void Stream_FilteredStreamExample()
{
    SqlConnection conn = new SqlConnection(@"Data Source=********************");
    conn.Open();

    for (; ; )
    {
        try
        {
            var stream = Stream.CreateFilteredStream();
            //stream.AddLocation(Geo.GenerateLocation(-180, -90, 180, 90));
            stream.AddTweetLanguageFilter(Language.English);
            stream.AddTrack("#TubeStrike");

            var timer = Stopwatch.StartNew();

            stream.MatchingTweetReceived += (sender, args) =>
            {

                var tweet = args.Tweet;

                if (timer.ElapsedMilliseconds > 1000)
                {
                    Console.WriteLine("{0}, {1}", tweet.IdStr, tweet.Text);
                    timer.Restart();
                }
            };

            stream.StartStreamMatchingAllConditions();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception: {0}", ex.Message);
        }
    }
}

您要使用以下代码:

stream.StreamStopped += (sender, args) =>
{
     stream.StartStreamMatchingAllConditions();
};
更多详情请访问。