Events in VB.NET


We’ve been getting a few questions on how to use RSS Platform events in VB.NET. The problem faced by most inquiries was the fact that the interface returned by the GetWatcher() method call couldn’t be cast to the FeedFolderWatcher or FeedWatcher type. Instead the returned interface can be cast to IFeedFolderEvents_Event or IFeedEvents_Event interface. As done here:



Imports Microsoft.Feeds.Interop


Module Module1



Dim WithEvents watcher As IFeedFolderEvents_Event


Sub Main()



Dim fm As IFeedsManager = New FeedsManager()


Dim rootFolder As IFeedFolder = fm.RootFolder


watcher = rootFolder.GetWatcher(FEEDS_EVENTS_SCOPE.FES_ALL, FEEDS_EVENTS_MASK.FEM_FOLDEREVENTS)


AddHandler watcher.FeedDownloading, AddressOf watcher_Downloading


End Sub


Sub watcher_Downloading(ByVal path As String)



Console.WriteLine(“Downloading {0}”, path)


End Sub


Sub watcher_DownloadCompleted(ByVal path As String, ByVal err As FEEDS_DOWNLOAD_ERROR) Handles watcher.FeedDownloadCompleted



Console.WriteLine(“Downloaded {0}”, path)


End Sub


End Module


 


The key is the highlighted part.


Note: We are aware that the IFeedFolderEvents_Event and IFeedEvents_Event interfaces do not appear in the Object Browser or in IntelliSense. We are looking into it.


Keep the feedback coming!


-Walter vonKoch

Comments (20)

  1. cool

    thanks

    this helps me a lot, i had a solution before ( tray icon notification) but the path was empty in folderitemcountchanged event

    now i use downloadcompleted

    Add question: sometime RSS downloading stops, only machine restarts help. Any idea?

    ps: private mail hannesp [AT] ppedv.de

  2. Andrew Davey says:

    I still think getting a decent managed wrapper is a top priority. All this COM interop is going to be a huge barrier to entry for morts who just want to play with MSFeeds.

  3. rss says:

    Andrew, am I correct to infer that by "all this com interop" you mean that it’s necessary to cast the returned objects to the correct interfaces?

    – Walter [MSFT]

  4. Ron says:

    Thanks for posting this Walter.  I wanted to add that it’s not necessary to include the AddHandler instructions in VB.net.

    If you have …

    Dim WithEvents watcher As IFeedFolderEvents_Event

    … all you need is the corresponding subroutine definition that includes the "handles" option.

    Sub watcher_DownloadCompleted(ByVal path As String, ByVal err As FEEDS_DOWNLOAD_ERROR) Handles watcher.FeedDownloadCompleted

    In fact, Visual Studio will build the sub routine stub for you if you select the appropriate class name and method name in the code view drop drowns.

    Regards,

    Ron

  5. rss says:

    Ron, you are correct, it’s not necessary to include the AddHanlder instruction. I used both methods in the code sample so people can choose according to their preference.

    I should have mentioned that in the post. Thanks for pointing it out!

    -Walter [MSFT]

  6. denkel says:

    Hi, I’m Asbjørn. Don’t know if this is the right place to subscribe this problem, but her I go.

    We have some problems with RSS and the new IE7.2. The RSS-feeds works fine, but the homepage where we publish ours RSS-news doesn’t work in the browser. It look’s like the browser is taking a screen dump of the RSS-news, so you can’t scroll in the news. This wasn’t a problem in the old IE. We will like to have both the feeds and the browser working. The URL for the problem is http://www.econ.ku.dk/polit/news.asp.

    My question: Is this script error, and if yes, what are the soloution? Or will the problem be solved in the new IE?  

  7. program says:

    Very good . You are doing a great job.

  8. LFERC says:

    Thanks for posting this Walter.  I wanted to add that it’s not necessary to include the AddHandler instructions in VB.net.

    If you have …

    Dim WithEvents watcher As IFeedFolderEvents_Event

    … all you need is the corresponding subroutine definition that includes the "handles" option.

    Sub watcher_DownloadCompleted(ByVal path As String, ByVal err As FEEDS_DOWNLOAD_ERROR) Handles watcher.FeedDownloadCompleted

    In fact, Visual Studio will build the sub routine stub for you if you select the appropriate class name and method name in the code view drop drowns.

    Regards,

    Ron

  9. Vista says:

    cool

    thanks

    this helps me a lot, i had a solution before ( tray icon notification) but the path was empty in folderitemcountchanged event

    now i use downloadcompleted

    Add question: sometime RSS downloading stops, only machine restarts help. Any idea?

    ps: private mail hannesp [AT] ppedv.de

  10. I still think getting a decent managed wrapper is a top priority. All this COM interop is going to be a huge barrier to entry for morts who just want to play with MSFeeds.

  11. Webhosting says:

    Ron, you are correct, it’s not necessary to include the AddHanlder instruction. I used both methods in the code sample so people can choose according to their preference.

    I should have mentioned that in the post. Thanks for pointing it out!

    -Walter [MSFT]

  12. Thisare says:

    Hi, I’m Asbjørn. Don’t know if this is the right place to subscribe this problem, but her I go.

    We have some problems with RSS and the new IE7.2. The RSS-feeds works fine, but the homepage where we publish ours RSS-news doesn’t work in the browser. It look’s like the browser is taking a screen dump of the RSS-news, so you can’t scroll in the news. This wasn’t a problem in the old IE. We will like to have both the feeds and the browser working. The URL for the problem is http://www.econ.ku.dk/polit/news.asp.

    My question: Is this script error, and if yes, what are the soloution? Or will the problem be solved in the new IE?  

  13. Nice solution. I’ve been looking for this.

  14. Kosmetyki says:

    Hi,

    Article written respectable. It has helped me a lot.

    Thanks

  15. Very good job. Very good info. Do it.

  16. Paul says:

    Thank you. I’ve been thinking about this solution for a two days, but i this script is error in IE

  17. Suplementy says:

    Very useful information

    thanks

  18. Rules says:

    he RSS-feeds works fine, but the homepage where we publish ours RSS-news doesn’t work in the browser.

  19. I’m searching for this solution. Thank you!

  20. Cool post ! Very useful. Thx for that.