Solved

Class Library Delegate Event Passing To Another Executable?

Posted on 2012-12-28
8
254 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

10 Experts available now in Live!

Get 1:1 Help Now