如何有一个函数在VB.net运行回调 [英] How to have a function run a callback in VB.net

查看:261
本文介绍了如何有一个函数在VB.net运行回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怕我一直在谷歌搜索这一点,但无法找到我明白一个答案,或者可以使用。

I'm afraid I have been Googling this, but can't find an answer that I understand, or can use.

在Javascript中,你可以运行一个功能,并设置其第一个函数运行后它会调用回调函数:

In Javascript, you can run a function and set a callback function which it calls after the first function has run:

function doThis(callBack){
    // do things
    // do things
    if(callBack){
         callBack();
    }
}

通过调用此: doThis(函数(){警报(完成)});

所以之后它的完成做事调用警报,告诉你,它的完成。

So after it's finished doing things it calls an alert to tell you it's done.

但你如何在VB.NET做同样的服务器端?

But how do you do the same server-side in VB.NET?

推荐答案

只要创建接受一个的 动作委托作为参数:

Just create a method that takes an Action delegate as parameter:

Sub DoThis(callback as Action)

    'do this
    'do that

    If Not callback Is Nothing Then
        callback()
    End If

End Sub

,你可以这样调用它

and you can call it like

DoThis(Sub() Console.WriteLine("via callback!"))

这篇关于如何有一个函数在VB.net运行回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆