?
Solved

Class Library Delegate Event Passing To Another Executable?

Posted on 2012-12-28
8
Medium Priority
?
261 Views
Last Modified: 2013-01-12
Me again, this time building a Class Library with a  Delegate and Event which I would like to pass it's Status to Form1 in another executable. Here's what I have so far, it doesn't error, just doesnt' show in the Form1 textbox. I'm guessing it's a threading issue.

Note: the 'FtpClientStatusEventHandler' and event works within it's own project.

My ultimate goal is to pass status messages from my .dll class library to any subscribing exe or possibly another .dll

[.dll]
namespace FtpClientManager
{
    public delegate void FtpClientStatusEventHandler(string statusMessage);

    public interface IFtpClient
    {        
        event FtpClientStatusEventHandler StatusMessage;
     }
}  

[.exe]
using FtpClientManager;

 public partial class Form1 : Form
 {
        IFtpClient ftpClient = new FtpClient();

        public Form1()
        {
            InitializeComponent();
         
            ftpClient.StatusMessage += new FtpClientStatusEventHandler(ftpClient_StatusMessage);
        }

 void ftpClient_StatusMessage(string statusMessage)
        {
            if (textBox2.InvokeRequired)
            {
                textBox2.Invoke((MethodInvoker)delegate { textBox2.Text = textBox2.Text + "\n\n" + statusMessage; });
            }
            else
            {
                textBox2.Text = textBox2.Text + "\n\n" + statusMessage;
            }
        }
}
0
Comment
Question by:pointeman
[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
  • 4
  • 4
8 Comments
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 38728826
try using like this
 void ftpClient_StatusMessage(string statusMessage)
        {
                textBox2.Text = textBox2.Text + "\n\n" + statusMessage;
        }

Open in new window

0
 

Author Comment

by:pointeman
ID: 38732473
1. I run a debugger and no message is getting to the 'statusMessage'.
2. No errors, just not showing message.
3. I have referenced the .dll correctly like so:

using FtpClientManager;

public partial class Form1 : Form
    {     
        IFtpClient ftpClient = new FtpClient();

        public Form1()
        {
            InitializeComponent();

            ftpClient.StatusMessage += new FtpClientStatusEventHandler([b]ftpClient_StatusMessage[/b]); //is active on Form1 load
        }

void ftpClient_StatusMessage(string [b]statusMessage[/b]) // no message here
        {
            textBox2.Text = textBox2.Text + "\n\n" + statusMessage;
        }
      

Open in new window

0
 
LVL 19

Accepted Solution

by:
Melih SARICA earned 2000 total points
ID: 38735917
Are u sure that dll ftpclient Sending  Status messages  ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:pointeman
ID: 38747414
Yes, because it works within a Desktop app.
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 38749080
Are u sure ur handling the correct event? There can be something to handle that event. or Insome cases i saw that u must set a percentange for the client to triggered event.
0
 

Author Comment

by:pointeman
ID: 38750444
Well then can you write some code to make your point?
0
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 38751234
Do u ave ur FTP client's Soucer Code ? The DLL one..
If not.. if its a Shareware or freeware what is ur DLL FTP Clients Name..
0
 

Author Closing Comment

by:pointeman
ID: 38770924
The FTP client code is running synchronous and blocking, so the message delegate is not working.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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