Udostępnij za pośrednictwem


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

  • Anonymous
    June 08, 2006
    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

  • Anonymous
    June 08, 2006
    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.

  • Anonymous
    June 14, 2006
    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]

  • Anonymous
    June 19, 2006
    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

  • Anonymous
    June 19, 2006
    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]

  • Anonymous
    June 27, 2006
    The comment has been removed

  • Anonymous
    August 19, 2007
    Very good . You are doing a great job.

  • Anonymous
    January 18, 2008
    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

  • Anonymous
    January 18, 2008
    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

  • Anonymous
    January 18, 2008
    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.

  • Anonymous
    January 18, 2008
    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]

  • Anonymous
    January 18, 2008
    The comment has been removed

  • Anonymous
    March 19, 2008
    Nice solution. I've been looking for this.

  • Anonymous
    April 13, 2008
    Hi, Article written respectable. It has helped me a lot. Thanks

  • Anonymous
    April 23, 2008
    Very good job. Very good info. Do it.

  • Anonymous
    August 14, 2008
    Thank you. I've been thinking about this solution for a two days, but i this script is error in IE

  • Anonymous
    August 23, 2008
    Very useful information thanks

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

  • Anonymous
    August 25, 2008
    I'm searching for this solution. Thank you!

  • Anonymous
    December 21, 2008
    Cool post ! Very useful. Thx for that.