Search code examples
.netvb.netasync-awaitcallbyname

How do I use CallByName or Invoke with Async/Await


CallByName and Invoke are not async functions so I can't call them asynchronously using the obvious syntax like:

rv = await CallByName(objScripts, txtScript.Text, CallType.Method)

Apparently I am the only one to ever need this so no answers on the internet.

My use case is I have hundreds of database transformation scripts written in vb.net. I have a database of which script processes which database. My code then reads the database and processes each script as the updated databases arrive, or I can select the script from a dropdown in my UI and run it that way.

I now need to run some of theses scripts async so I can use PuppeteerSharp to scrape some data rather use a database.

So how do I make that work?


Solution

  • Just cast the result to Task and await it

    rv = Await DirectCast(CallByName(objScripts, txtScript.Text, CallType.Method), Task)