Solved

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

Posted on 2014-10-01
3
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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