What does this C # code mean?

Can someone explain this to me. I have this code, but I don’t know what that means.

void ConnectionManager_ConnectionFailed(object sender, EventArgs e)
{
    BeginInvoke((MethodInvoker)delegate()
    {
        if (cbAutoConnect.Checked)
            Connect();
        else
            State = ConnectState.NotFound;
    });
}

My question is:

  • Is this method an EventHandler?

  • What is the purpose of this code?

    BeginInvoke ((MethodInvoker) delegate () {

  • What happened to the "Condition" when the "Else" condition was met?

Note:

Connection is a method.

Status is an enumeration describing 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 tip

Enumeration Initiation

public enum ConnectState { Connected, Connecting, NotFound }
ConnectState _State = ConnectState.NotFound;

I don't know what it is for sure, but I think it is a custom EventHandler declaration for the ConnectState object / class.

public EventHandler<EventArgs<ConnectState>> StateChanged;
+3
source share
3 answers

Is this method an EventHandler?

Yes it is.

What is the purpose of this code?

delegate { ... }, MethodInvoker Control.BeginInvoke, , .

"" "Else"?

cbAutoConnect.Checked - true Connect , State's ConnectState.NotFound, .

+2

, . , , , "NotFound", ConnectionState

,

+1

1, , , , , . 2 asyn excute ()
3 er ~~ .

Take a look at this: case ConnectState.NotFound: Do something; after setting the value, it is not finished, if the state is changed, continue DoingSomeThing.

-2
source

All Articles