Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.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#到VB.NET转换错误,请提供建议_C#_Vb.net_C# To Vb.net - Fatal编程技术网

C#到VB.NET转换错误,请提供建议

C#到VB.NET转换错误,请提供建议,c#,vb.net,c#-to-vb.net,C#,Vb.net,C# To Vb.net,我正在尝试将以下C#代码段翻译为VB: public bool ShowHandlerDialog(string message) { Message = message; Visibility = Visibility.Visible; _parent.IsEnabled = false; _hideRequest = false; while (!_hi

我正在尝试将以下C#代码段翻译为VB:

public bool ShowHandlerDialog(string message)
        {
            Message = message;
            Visibility = Visibility.Visible;

            _parent.IsEnabled = false;

            _hideRequest = false;
            while (!_hideRequest)
            {
                // HACK: Stop the thread if the application is about to close
                if (this.Dispatcher.HasShutdownStarted ||
                    this.Dispatcher.HasShutdownFinished)
                {
                    break;
                }

                // HACK: Simulate "DoEvents"
                this.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
                Thread.Sleep(20);
            }

            return _result;
        }
但是翻译在这一行中给出了一个错误:

this.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
译文是:

Me.Dispatcher.Invoke(DispatcherPriority.Background, New ThreadStart(Function() Do End Function))
新线程启动后,它似乎无法正确转换位。有人能解释一下“
delegate{}
”在英语中的作用吗

new ThreadStart(delegate {}));

我该如何纠正翻译错误?谢谢你的建议

该行只是启动一个新线程并等待它完成。“delegate{}”代码只是一个匿名/内联方法(我认为VB.NET不支持这种方法);就像你基本上会指向一个空方法一样。例如,在c#中,事件处理程序可以绑定到匿名(内联)委托方法,如下所示:

this.OnClick += (EventHandler)delegate(object sender, EventArgs ea) {
    MessageBox.Show("Click!");
};
上面的评论是[//HACK:Simulate“DoEvents”]。只需将这两行代码替换为适用于VB.NET的DoEvents,就可以进行设置。这样,其他线程就可以在继续之前完成它们的工作,从而提高响应能力

希望这有帮助