SoFunction
Updated on 2025-03-06

C# WinForm cross-thread access control instance

This article describes the implementation method of WinForm cross-thread access control in C#, and is shared with you for your reference.

The specific implementation method is as follows:

1. Cross-thread access control delegates and class definitions

Copy the codeThe code is as follows:
using System;
using ;

namespace
{
    /// <summary>
/// Delegation of cross-thread access control
    /// </summary>
    public delegate void InvokeDelegate();

    /// <summary>
/// Cross-thread access control class
    /// </summary>
    public class InvokeUtil
    {
        /// <summary>
/// Cross-thread access control
        /// </summary>
/// <param name="ctrl">Form object</param>
/// <param name="de">Trust</param>
        public static void Invoke(Control ctrl, Delegate de)
        {
            if ()
            {
                (de);
            }
        }
    }
}

2. Usage

In the threading method of the file:

Copy the codeThe code is as follows:
InvokeDelegate invokeDelegate = delegate()
{
        = false;
        = false;
        = false;
        = false;
        = false;
};
(this, invokeDelegate);

I hope this article will be helpful to everyone's C# programming.