Solved

C# - How to implement event listener from this thirdparty COM

Posted on 2014-10-01
3
186 Views
Last Modified: 2014-10-21
Hi,

I am using a thirdparty DLL to initiate a download.

I'm told to use the following code snippet to be notified when the download is complete.

(svxFile.saver as _IStreamCollectorEvents_Event).stopped += (collector) => 
{ 
//do something
 };

Open in new window


How do I use this in a C# Console Application?  Where should it go? I cant the event to fire no matter where I put it.

Thank you

static class Program
    {
        static SVXFile file_ = new SVXFile();        

        static void Main(string[] args)
        {            
            (file_.saver as _IStreamCollectorEvents_Event).stopped += (collector) => { Console.WriteLine("Download Result: " + collector.ToString()); };
            (file_.saver as _IStreamCollectorEvents_Event).failed += (sender,error) => { Console.WriteLine("Download Result: " + error.message); };
            
            //Download code removed
            
            Console.WriteLine("Done");
            Console.Read();
        }        
    }

Open in new window

0
Comment
Question by:mhdi
  • 2
3 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Anywhere before you actually use the component, I suspect. I imagine Main should be fine.
0
 

Author Comment

by:mhdi
Comment Utility
Hmm. Thats where I have it and I still can't get it to fire. What's the best way to debug these kinds of events?
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
There nothing overly special about events. They are just special implementations of the Observer Pattern created as a language feature of .NET. You should be able to debug them like any other method. Are you certain your external component is raising the event? Is there some flag you have to set?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now