I am having fun with TweetInvi in VB.Net, unfornately I have issue with converting this code to VB.Net. I am still beginner and I was trying to get some information about RaiseEvent, but I couldn't do it. Here is code. I want to run this in button event:
var stream = Stream.CreateFilteredStream();
stream.AddTrack("tweetinvi");
stream.MatchingTweetReceived += (sender, args) =>
{
Console.WriteLine("A tweet containing 'tweetinvi' has been found; the tweet is '" + args.Tweet + "'");
};
stream.StartStreamMatchingAllConditions();
Thanks.
As a matter of fact you're not trying to raise an event, but subscribe to one. The IntelliSense error that you get when converting that code to VB.NET is unfortunately a bit misleading.
In terms of events, C#'s
+=
operator is equal toDelegate.Combine()
which adds another delegate to an event's subscribers list (list of event handlers). ADelegate
is simply a class holding the pointer of another method. Delegates are used to provide an easy way of passing around and invoking methods through code.Quoting the documentation:
To subscribe to events in VB.NET you gotta use the
AddHandler
statement, which's syntax is:Thus:
- The underscore (
_
) on the end is just a way of telling the compiler to continue on the next line. In the newer versions of VB.NET this isn't necessary, but some people still use VS 2008 and below... I also like to have it there to make it more clear which statements go together and which not.