Here's a slight variation on Ron Beyer's solution, and I encourage you to vote his solution 5.
public static class A
{
private static bool _isConnected;
public static bool IsConnected
{
get { return _isConnected; }
set
{
_isConnected = value;
OnConnectedChanged(_isConnected);
}
}
public static event EventHandler ConnectedChanged;
private static void OnConnectedChanged(bool boolValue)
{
if (ConnectedChanged != null)
ConnectedChanged(boolValue, EventArgs.Empty);
}
}
A sample test:
private void Form1_Load(object sender, EventArgs e)
{
A.ConnectedChanged += A_ConnectedChanged;
A.IsConnected = false;
A.IsConnected = true;
A.IsConnected = false;
}
private void A_ConnectedChanged(object sender, EventArgs e)
{
Console.WriteLine(sender.ToString());
}
Note: it's certainly more "standard," and probably better practice, to define a Custom EventArgs Class to pass the boolean value to subscribers to the notification Event. I have never used a Custom EventArgs in a static context before, and I am curious to try it, to see if there are any "gotchas."
Meanwhile, just accessing the static bool in the Class in EventHandlers is easy enough !