Brief analysis of callback mechanism of C

  • 2020-11-25 07:28:37
  • OfStack

This article briefly analyzes the callback mechanism of C#. Share to everybody for everybody reference. The specific analysis is as follows:

1. Callbacks sound lofty, but they are essentially delegates. Callbacks are one application of delegates, and they are essentially delegates.

2.1 General callbacks are mostly in threads and are therefore declared class - level variables. (At the same level as a class, not a local variable inside a method).

3. The Settings:

Form1.CheckForIllegalCrossThreadCalls = false;
Setting false to check for valid cross-thread calls means not checking that this is not allowed in project development, so BUG is not thread safe.

4. Initialize the callback method (essentially instantiating the delegate).

5. The thread must be started before the blocking operation, or it will wait for the blocking operation to complete before starting the thread.

6. Settings:

pgProgressBar2.Invoke(setProgressBarValueCallBack, i);

The action that triggers the action of the action object (which is essentially the Invoke method that passes the delegate as a parameter to the control, and is specifically used to accept the delegate).

Hopefully this article has helped you with your C# programming.


Related articles: