Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何取消正在进行的'Refresh()`进程?_C#_.net_Winforms - Fatal编程技术网

C# 如何取消正在进行的'Refresh()`进程?

C# 如何取消正在进行的'Refresh()`进程?,c#,.net,winforms,C#,.net,Winforms,我的应用程序有一些需要重新绘制屏幕的绑定参数,有些参数会导致重新绘制的时间稍长 我创建了一个接口,用我的访问器处理这个问题,因此对于需要这个的参数,我调用NotifyRedrawRequired(),这最终导致调用this.Refresh() 我的代码: public delegate void MyFormDrawRequiredEventHandler(object sender, string callerName); public MyForm() : Form { publi

我的应用程序有一些需要重新绘制屏幕的绑定参数,有些参数会导致重新绘制的时间稍长

我创建了一个接口,用我的访问器处理这个问题,因此对于需要这个的参数,我调用
NotifyRedrawRequired()
,这最终导致调用
this.Refresh()

我的代码:

public delegate void MyFormDrawRequiredEventHandler(object sender, string callerName);

public MyForm() : Form {
    public MyForm() {
        InitializeComponent();
        this.DoubleBuffered = true;

        this.ResizeRedraw = true;
        this.DrawRequired += MyForm_DrawRequired;
    }

    void MyForm_DrawRequired(object sender, string callerName) { this.Refresh(); }

    [Category("Action")]
    [Description("Fires when a redraw is required by the class.")]
    public event MyFormDrawRequiredEventHandler DrawRequired;

    protected virtual void NotifyDrawRequired([CallerMemberName] String callerName = "")
    {
        if (DrawRequired != null) { DrawRequired(this, callerName); }
    }

    private int blockSpacing;
    public int BlockSpacing
    {
        get { return blockSpacing; }
        set
        {
            if (blockSpacing != value)
            {
                blockSpacing = value;
                NotifyDrawRequired();
            }
        }
    }
    /// Rest of the form code ...
}

避免
Refresh()
事件堆积的最佳方法是什么?
取消
Refresh()
过程是一件简单的事情吗?

我花了很长时间才找到一个引用来刷新名称上的内存,但由于某些原因,这并不是100%的Winforms,这曾经是针对原始Windows API的半标准编程实践。您可以通过发送
WM_SETREDRAW
消息来重新启动它

当您这样做时,很大程度上取决于您的应用程序。我以前用定时器。在太短的时间内太多,请关闭它们。没有在一段时间内,或我们正在接近一对“电影帧”没有更新,打开他们回来

如果Windows无法更新该窗口,它将收集
无效
d矩形,以确定何时可以更新