Solved

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

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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

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!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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