How to keep streaming continuously - Tweetinvi

I adapted the following code from one I found on the internet. Works fine but doesn't work continuously and pulls in new tweets. What do I need to change? Help rate.

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

      

+3


source to share


1 answer


You want to use the following code:



stream.StreamStopped += (sender, args) =>
{
     stream.StartStreamMatchingAllConditions();
};

      

+2


source







All Articles