📜  自动化 InvokeRequired 代码模式 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:32.858000             🧑  作者: Mango

代码示例1
public static void InvokeIfRequired(this Control control, MethodInvoker action)
{
    // See Update 2 for edits Mike de Klerk suggests to insert here.

    if (control.InvokeRequired) {
        control.Invoke(action);
    } else {
        action();
    }
}


/// oder so
richEditControl1.InvokeIfRequired(() =>
{
    // Do anything you want with the control here
    richEditControl1.RtfText = value;
    RtfHelpers.AddMissingStyles(richEditControl1);
});