Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

New Post: Best Practices When Stopping and Starting a Filtered Stream In A Task

$
0
0
I'm kicking off a filtered stream like this:
Task.Factory.StartNew(filteredStream.StartStreamMatchingAllConditions);
At some dynamic event, I need to stop the stream, make a change to the keywords and then restart the stream. However, I need to act on the stream that's running inside the task I kicked off and let the code keep running. This is running in an Azure worker role and I'm updating a heartbeat and checking for the special event in parallel.

If I call filteredStream.StopStream() directly outside the task, it works great. When the stop delegate is called, I do what I need to inside that block and then restart the streaming again.

But, because the StopStream() method never returns from starting the stream again, the code just sits there at the call to StopStream().

If I kick off another task like this, it works:
Task.Factory.StartNew(filteredStream.StopStream);
However, I'm afraid that this will result in a resource leak because I'm kicking off another task every time the event is detected.

Does anyone have a best practice recommendation for acting on the stream that is started using Task.Factory.StartNew()?

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>