Ehm i'm not so practice with C# and API's,at the moment i'm using c# to imteplement twitter notifications to my software. But i have some issues with this code,when i try run this code the program seems to be in an infinite loop. Autentication works well cause i tried to post a new tweet and it works,this is the only part that have problems.
C#
private void Button1_Click(object sender, RoutedEventArgs e)
{
var credentials = TwitterCredentials.CreateCredentials("Access_Token", "Access_Token_Secret", "Consumer_Key", "Consumer_Secret");
TwitterCredentials.ExecuteOperationWithCredentials(credentials, () =>
{
var userStream = Stream.CreateUserStream();
userStream.TweetCreatedByMe += (s, a) => { text1.Text = ("I posted {0}"+ a.Tweet.Text); };
userStream.TweetCreatedByFriend += (s, a) => { text1.Text=("{0} posted {1}"+ a.Tweet.Creator.Name+ a.Tweet.Text); };
userStream.MessageReceived += (s, a) => { text1.Text =("You received the message : {0}"+a.Message.Text); };
userStream.StartStream();
});
}
Comments: ** Comment from web user: linvi **
C#
private void Button1_Click(object sender, RoutedEventArgs e)
{
var credentials = TwitterCredentials.CreateCredentials("Access_Token", "Access_Token_Secret", "Consumer_Key", "Consumer_Secret");
TwitterCredentials.ExecuteOperationWithCredentials(credentials, () =>
{
var userStream = Stream.CreateUserStream();
userStream.TweetCreatedByMe += (s, a) => { text1.Text = ("I posted {0}"+ a.Tweet.Text); };
userStream.TweetCreatedByFriend += (s, a) => { text1.Text=("{0} posted {1}"+ a.Tweet.Creator.Name+ a.Tweet.Text); };
userStream.MessageReceived += (s, a) => { text1.Text =("You received the message : {0}"+a.Message.Text); };
userStream.StartStream();
});
}
Comments: ** Comment from web user: linvi **
This is an infinite loop. You need to run the the stream in its own thread if you do not want to block the UI Thread.