How to make a very simple asynchronous method call in vb.net

You could do this with a simple thread:

Add :

 Imports System.Threading

And wherever you want it to run :

 Dim t As New Thread(New ThreadStart(AddressOf DoAsyncWork))
 t.Priority = Threading.ThreadPriority.Normal
 t.Start()

The call to t.Start() returns immediately and the new thread runs DoAsyncWork in the background until it completes. You would have to make sure that everything in that call was thread-safe but at first glance it generally seems to be so already.


I wouldn't recommend using the Thread class unless you need a lot more control over the thread, as creating and tearing down threads is expensive. Instead, I would recommend using a ThreadPool thread. See this for a good read.

You can execute your method on a ThreadPool thread like this:

System.Threading.ThreadPool.QueueUserWorkItem(AddressOf DoAsyncWork)

You'll also need to change your method signature to...

Protected Sub DoAsyncWork(state As Object) 'even if you don't use the state object

Finally, also be aware that unhandled exceptions in other threads will kill IIS. See this article (old but still relevant; not sure about the solutions though since I don't reaslly use ASP.NET).