Solved

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

Posted on 2014-10-01
3
197 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 75

Expert Comment

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

Author Comment

by:mhdi
ID: 40356216
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 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40356258
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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