1

Closed

Deadlock occurring during get samples stream example

description

I am using the code shown below that I got from the LinqToTwitter online documentation, to get sample statuses (LinqToTwitter 3.0.2). It's deadlocking. After the await call the UI is completely unresponsive. What am I doing wrong?

async private void btnTest_Click(object sender, RoutedEventArgs e)
    {
        TwitterContext twitterCtx = new TwitterContext(SharedState.Authorizer);

        /* Sample stream */
        Debug.WriteLine("\nStreamed Content: \n");
        int count = 0;

        await
            (from strm in twitterCtx.Streaming
             where strm.Type == StreamingType.Sample
             select strm)
            .StartAsync(async strm =>
            {
                Console.WriteLine(strm.Content + "\n");

                if (count++ >= 5)
                    strm.CloseStream();
            });

        Debug.WriteLine("Sample streams retrieved.");
}
Closed Jun 16 at 1:57 AM by JoeMayo
Fixed and deployed in LINQ to Twitter v3.0.4.

comments

JoeMayo wrote May 5 at 2:38 AM

I just checked in a change that should help avoid deadlocks. It's available in the downloadable source code.

roschler wrote May 5 at 5:04 AM

Thanks Joe. Is the change in the NuGet package yet?