Solved

Class Library Delegate Event Passing To Another Executable?

Posted on 2012-12-28
8
256 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 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