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

前端 未结 4 1826
南方客
南方客 2020-12-30 05:17

I just have a simple vb.net website that need to call a Sub that performs a very long task that works with syncing up some directories in the filesystem (details not importa

4条回答
  •  Happy的楠姐
    2020-12-30 05:56

    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.

提交回复
热议问题