Solved

Class Library Delegate Event Passing To Another Executable?

Posted on 2012-12-28
8
255 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
  • 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 500 total points
ID: 38735917
Are u sure that dll ftpclient Sending  Status messages  ?
0
 

Author Comment

by:pointeman
ID: 38747414
Yes, because it works within a Desktop app.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

864 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

23 Experts available now in Live!

Get 1:1 Help Now