Add the event to your library as follows:
public event Action<string> OnDataReceived = null;
Then in the application:
Library.Class a = new Library.Class(); a.OnDataReceived += receivedData; a.start(ip, port);
What is it.
But you can write events with conventions, and I suggest you start using it, because .NET uses events in this way, so whenever you come across this convention, you will know its events. Therefore, if I reorganize your code a little, it should be something like:
In your class library:
//... public class YourEventArgs : EventArgs { public string Data { get; set; } } //... public event EventHandler DataReceived = null; ... protected override OnDataReceived(object sender, YourEventArgs e) { if(DataReceived != null) { DataReceived(this, new YourEventArgs { Data = "data to pass" }); } }
When your class library wants to fire an event, it must call OnDataReceived, which is responsible for checking that someone is listening and creating the appropriate EventArgs to pass your data to the listener.
In the application, you must change your method signature:
Library.Class a = new Library.Class(); a.DataReceived += ReceivedData; a.start(ip, port);
source share