Streaming: Close a stream on demand

Oct 20, 2014 at 2:10 PM
Edited Oct 20, 2014 at 2:11 PM
Hello,

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;

            await
                (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;
                    Console.WriteLine(
                        (count + 1).ToString() + 
                        ". " + DateTime.Now + 
                        ": " + message + "\n");

                    if (closeRequested)
                        strm.CloseStream();
                });
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.

Thanks!
Coordinator
Oct 20, 2014 at 3: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
Coordinator
Oct 20, 2014 at 3:15 PM
Hi,

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

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

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