Can someone explain this to me. I Have code like this, but I don't know what the meaning.
void ConnectionManager_ConnectionFailed(object sender, EventArgs e)
{
BeginInvoke((MethodInvoker)delegate()
{
if (cbAutoConnect.Checked)
Connect();
else
State = ConnectState.NotFound;
});
}
My question:
Is this method an EventHandler?
What the purpose of this code is?
BeginInvoke((MethodInvoker)delegate() {
What happened to the "State" when execution condition "Else"?
Note:
Connect is a Method.
State is an enum describe by this code
public ConnectState State
{
get
{
return _State;
}
{
if (_State == value)
return;
_State = value;
switch (value)
{
case ConnectState.Connected:
DoingSomeThing;
break;
case ConnectState.Connecting:
DoingSomeThing;
break;
case ConnectState.NotFound:
DoingSomeThing;
break;
}
if (StateChanged != null)
StateChanged(this, new EventArgs<ConnectState>(value));
}
}
Another Hint
The enum initiation
public enum ConnectState { Connected, Connecting, NotFound }
ConnectState _State = ConnectState.NotFound;
I do not know what this exactly, but I think this is a custom EventHandler declaration for "ConnectState" object/class.
public EventHandler<EventArgs<ConnectState>> StateChanged;