如何在vb.net中使用DispatcherOperationCallback

发布于 2024-10-26 09:00:18 字数 1215 浏览 2 评论 0原文

我在使用 DispatcherOperationCallback 将 c# 转换为 vb.net 时遇到问题。

我尝试根据 将 c# 匿名转换为 vb 的帮助来转换它。 net

我正在使用 VS2010。

我有这样的 c# 代码:

    public void Callback(Contract contract)
    {
        Dispatcher.BeginInvoke(DispatcherPriority.Normal,
              (DispatcherOperationCallback)delegate(object arg)
              {
                  Contract obj = (Contract)arg;
                  txtRequest.Text = HandleArgument(obj);                      
                  return null;
              }, contract);
    }

在我尝试像这样更改为 vb.net 之后,

Public Sub Callback(ByVal contract As Contract) Implements IServiceCallback.Callback

    Dispatcher.BeginInvoke(New DispatcherOperationCallback(Sub(arg As Object)
                                                           txtRequest.Text = HandleArgument(DirectCast(arg, Contract))
                                                           End Sub), DispatcherPriority.Normal, contract)

End Sub

但它不起作用。 vs2010显示“嵌套子没有与委托兼容的签名“委托函数DispatcherOperationCallback(arg As Object) As Object”

谢谢您的帮助。

I have a problem with coverting c# to vb.net on using DispatcherOperationCallback.

I have tried to convert it based on help to convert c# anonymous to vb.net

I'm using VS2010.

I have a c# code like this:

    public void Callback(Contract contract)
    {
        Dispatcher.BeginInvoke(DispatcherPriority.Normal,
              (DispatcherOperationCallback)delegate(object arg)
              {
                  Contract obj = (Contract)arg;
                  txtRequest.Text = HandleArgument(obj);                      
                  return null;
              }, contract);
    }

And After I tried to change to vb.net like this

Public Sub Callback(ByVal contract As Contract) Implements IServiceCallback.Callback

    Dispatcher.BeginInvoke(New DispatcherOperationCallback(Sub(arg As Object)
                                                           txtRequest.Text = HandleArgument(DirectCast(arg, Contract))
                                                           End Sub), DispatcherPriority.Normal, contract)

End Sub

but it did not work. The vs2010 displayed "nested sub does not have a signature that is compatible with delegate "Delegate Function DispatcherOperationCallback(arg As Object) As Object"

Thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情栀口红 2024-11-02 09:00:18

只需阅读错误消息:

nested sub does not have a signature that is compatible with delegate 
  "Delegate Function DispatcherOperationCallback(arg As Object) As Object

因此,您应该相应地更改代码。

Public Sub Callback(ByVal contract As Contract) Implements IServiceCallback.Callback
    Dispatcher.BeginInvoke(
      New DispatcherOperationCallback(
          Function(arg As Object)
              txtRequest.Text = HandleArgument(DirectCast(arg, Contract))
              Return Nothing ' // you need to check what should be returned here '
          End Function), 
         DispatcherPriority.Normal, 
         contract)
End Sub

Just read the error message:

nested sub does not have a signature that is compatible with delegate 
  "Delegate Function DispatcherOperationCallback(arg As Object) As Object

so, you should change you code accordingly.

Public Sub Callback(ByVal contract As Contract) Implements IServiceCallback.Callback
    Dispatcher.BeginInvoke(
      New DispatcherOperationCallback(
          Function(arg As Object)
              txtRequest.Text = HandleArgument(DirectCast(arg, Contract))
              Return Nothing ' // you need to check what should be returned here '
          End Function), 
         DispatcherPriority.Normal, 
         contract)
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文