Answer the question
In order to leave comments, you need to log in
How to bind event across multiple classes?
Good afternoon!
Faced a huge problem for me, tk. I’ve never dealt with events before, but right now I just need to use them :(
I’ll write the question itself like this: there are 1 dll, 2 classes, you need to bind an Event that will be signed in the main console application, from class 1 event is called which is in class 2 "Maybe I wrote it wrong. I just don't understand a bit about event.
I did this (next), but when I subscribe from the main project, there is nothing.
public class Test
{
public void Add(string text)
{
OnMessage(text);
}
public event Action<string> OnMessage;
}
Test t = new Test();
t.Add(StringResponse);
Test t = new Test();
t.OnMessage += tcp_OnMessage;
Answer the question
In order to leave comments, you need to log in
In any case, the subscription must be before abandoned messages, otherwise they will be lost, in this case there will be an exception in general, because there is no check for null
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question