This is a method in the other class that i want to get the message from in my mainform.
string message = Encoding.ASCII.GetString(data);
Console.WriteLine(message);
Can i subscribe to this method from the main method somehow to get the data each time this method is triggered?
Edit: Okay so this is what my code looks like now:
} else {
string message = Encoding.ASCII.GetString(data);
DoSomething(message);
//Console.WriteLine(message);
}
} catch (Exception ex) {
Log("Error recieving data: " + ex.ToString());
}
}
}
public delegate void SomethingHappenedHandler(string s);
public SomethingHappenedHandler SomethingHappened = null;
public void DoSomething(string message)
{
Console.WriteLine(message);
var sh = SomethingHappened;
if (sh == null)
{
sh(message);
}
}
And in the main method:
dht.dhtNode.SomethingHappened += (msg) =>
{
talkText.Text += "[Friend]: " + msg + "\n\n";
};
But it does not trigger it? what else should i do to make it work?