Automation server with events

Hello!

I'm trying to develop a small automation dll server in C#.

Everything was fine until I got to events, which I was unable to do.

What I did, was something like :

File | New Project...
Selected "Class Library"
Some of the code was :

// Properties
public string SetEquipmentName
            {
                  set
                  {
                        strEquipmentName = value;
                  }
            }

// Methods
public void Initialize()
            {
                  try
                  {
                        MessageBox.Show ("Initialize");
                  }
                  catch (Exception e)
                  {
                  }
            }


// etc...

This is working fine with the clients, but I need to do throw events like :

void OnEquipmentConnect()
void OnEquipmentDisconnect (int ErrorCode, ref string ErrorText)

etc.

Please help me.

Thank you

Joao
LVL 1
jpcsAsked:
Who is Participating?
 
moduloCommented:
PAQed with points refunded (250)

modulo
Community Support Moderator
0
 
Razzie_Commented:
In your namespace, declare the delegates:

public delegate void OnEquipmentConnect();
public delegate void OnEquipmentDisconnect(int ErrorCode, string ErrorText);

in your class, declare the events:

public event OnEquipmentConnect Connect;
public event OnEquipmentDisconnect Disconnect;

and somewhere in your code, use:

public void Connect() // or some other method you have that does the connecting part
{
    if(this.Connect != null)
        this.Connect();
}


and do the same for the Disconnect Event.

This should work - you can now use something like:

Automation.Server server = new Automation.Server();
server.Connect += new OnEquipmentConnect(server_Connect);

private void server_Connect()
{
    // your code here
}


That's about I think.
HTH,

Razzie
0
 
jpcsAuthor Commented:
Hello Razzie,

I'm sorry but this didn't work.


I forgot to mention one thing that might be important...

The client application is writte in VB or Delphi or C++ Builder


Regards,

Joao
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
jpcsAuthor Commented:
Well,

looks like I've found the answer to my question here : http://www.gekko-software.nl/DotNet/BigStory/AutomationInDotNet.htm

Hope this helps someone!


Thanks for the help.

Joao
0
 
Razzie_Commented:
I kinda misread the question, the author solved it, so I say PAQ / Refund.
0
 
jpcsAuthor Commented:
Thanks Razzie_

Joao
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.