This project has moved and is read-only. For the latest updates, please go here.

Streaming: Close a stream on demand

Oct 20, 2014 at 3:10 PM
Edited Oct 20, 2014 at 3:11 PM

I am working on a windows service that is capable of streaming the tweets from a user. Everything is working fine but I am trying to figure out a way to close gracefully. Based on the example available, I came up with the following snippet.
            Console.WriteLine("\nStreamed Content: \n");
            bool closeRequested = false;

                (from strm in twitterCtx.Streaming
                 where strm.Type == StreamingType.User
                 select strm)
                .StartAsync(async strm =>
                    string message = 
                        string.IsNullOrEmpty(strm.Content) ? 
                            "Keep-Alive" : strm.Content;
                        (count + 1).ToString() + 
                        ". " + DateTime.Now + 
                        ": " + message + "\n");

                    if (closeRequested)
The problem with the code is that when "closeRequested" is set to true, it is only taken into account on the next stream. Is there a way to close the streaming immediately? Otherwise, I will code some retry/sleep on the close event of my service.

Oct 20, 2014 at 4:11 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Marked as answer by grigmin on 10/20/2014 at 11:56 AM
Oct 20, 2014 at 4:15 PM

I've noticed this too. I copied this to a work-item to take a closer look.

Marked as answer by grigmin on 10/20/2014 at 11:56 AM
Oct 20, 2014 at 7:56 PM
Great Thanks.

In the meantime, I'll work out a workaround in my code.