[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Class Library Delegate Event Passing To Another Executable?

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
pointeman
Asked:
pointeman
  • 4
  • 4
1 Solution
 
Melih SARICACommented:
try using like this
 void ftpClient_StatusMessage(string statusMessage)
        {
                textBox2.Text = textBox2.Text + "\n\n" + statusMessage;
        }

Open in new window

0
 
pointemanAuthor Commented:
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
 
Melih SARICACommented:
Are u sure that dll ftpclient Sending  Status messages  ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
pointemanAuthor Commented:
Yes, because it works within a Desktop app.
0
 
Melih SARICACommented:
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
 
pointemanAuthor Commented:
Well then can you write some code to make your point?
0
 
Melih SARICACommented:
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
 
pointemanAuthor Commented:
The FTP client code is running synchronous and blocking, so the message delegate is not working.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now