我有一个简单的vb.net网站,需要调用一个子程序,该子程序执行与文件系统中某些目录同步的非常长时间的任务(细节不重要)。
当我调用该方法时,网站最终会超时等待子例程完成。然而,即使网站超时,该例程最终也会完成其任务,并且所有目录都会按照预期进行更新。
我想要防止超时,因此我想异步调用Sub。我不需要(甚至不想要)任何回调/确认它是否成功运行。
那么,如何在VB.net网站内异步调用我的方法?
如果需要一些代码:
当我调用该方法时,网站最终会超时等待子例程完成。然而,即使网站超时,该例程最终也会完成其任务,并且所有目录都会按照预期进行更新。
我想要防止超时,因此我想异步调用Sub。我不需要(甚至不想要)任何回调/确认它是否成功运行。
那么,如何在VB.net网站内异步调用我的方法?
如果需要一些代码:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call DoAsyncWork()
End Sub
Protected Sub DoAsyncWork()
Dim ID As String = ParentAccountID
Dim ParentDirectory As String = ConfigurationManager.AppSettings("AcctDataDirectory")
Dim account As New Account()
Dim accts As IEnumerable(Of Account) = account.GetAccounts(ID)
For Each f As String In My.Computer.FileSystem.GetFiles(ParentDirectory)
If f.EndsWith(".txt") Then
Dim LastSlashIndex As Integer = f.LastIndexOf("\")
Dim newFilePath As String = f.Insert(LastSlashIndex, "\Templates")
My.Computer.FileSystem.CopyFile(f, newFilePath)
End If
Next
For Each acct As Account In accts
If acct.ID <> ID Then
Dim ChildDirectory As String = ConfigurationManager.AppSettings("AcctDataDirectory") & acct.ID
If My.Computer.FileSystem.DirectoryExists(ChildDirectory) = False Then
IO.Directory.CreateDirectory(ChildDirectory)
End If
My.Computer.FileSystem.DeleteDirectory(ChildDirectory, FileIO.DeleteDirectoryOption.DeleteAllContents)
My.Computer.FileSystem.CopyDirectory(ParentDirectory, ChildDirectory, True)
Else
End If
Next
End Sub