Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.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# 使用Application.DoEvents()时如何抑制叮当声_C#_Winforms_Keydown - Fatal编程技术网

C# 使用Application.DoEvents()时如何抑制叮当声

C# 使用Application.DoEvents()时如何抑制叮当声,c#,winforms,keydown,C#,Winforms,Keydown,在文本框上使用KeyDown事件时,如果要使用命令Application.DoEvents(),是否有方法抑制叮当声?我使用此命令刷新屏幕(否则在函数DoSomething()完成之前不会有任何可见的更改) void TbTextKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Return) { e.Handled = true; e.Su

在文本框上使用KeyDown事件时,如果要使用命令Application.DoEvents(),是否有方法抑制叮当声?我使用此命令刷新屏幕(否则在函数DoSomething()完成之前不会有任何可见的更改)

    void TbTextKeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Return) {
            e.Handled = true;
            e.SuppressKeyPress = true;  
            Application.DoEvents(); // this command triggers the Ding
            DoSomething(); // this function may take a few seconds to complete
        }
    }

Windows配置面板/声音/系统?谢谢,但如果可能的话,我希望不要干扰系统声音。
async void TbTextKeyDown
wait Task.Run(()=>DoSomething())
不带
DoEvents()
e.SuppressKeyPress无法工作当您执行此操作时,DoEvents会在按键被抑制之前触发KeyPress事件。这只是DoEvents导致的许多重入问题中的另一个。不要这样做。您没有留下足够的面包屑来猜测到底需要更新什么,请从这个开始。Update()。此外,您只需要
e.SuppressKeyPress=true;
。此属性还可以在内部设置
e.Handled=true;
。您不应该在
KeyDown
事件中运行花费那么多时间来完成的方法。您应该提及此代码应该执行的任务。同步方法将阻止用户键入,异步方法将阻止用户键入造成麻烦的是,你需要先处理上一个问题,然后再开始另一个问题,最终等等。