Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:06:57+00:00 2026-06-03T08:06:57+00:00

I just have a simple vb.net website that need to call a Sub that

  • 0

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 important).

When I call the method, it eventually times out on the website waiting for the sub routine to complete. However, even though the website times out, the routine eventually completes it’s task and all the directories end up as they should.

I want to just prevent the timeout so I’d like to just call the Sub asynchronously. I do not need (or even want) and callback/confirmation that it ran successfully.

So, how can I call my method asynchronously inside a website using VB.net?

If you need to some code:

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:06:58+00:00Added an answer on June 3, 2026 at 8:06 am

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple Mac Cocoa app that just has a Web View
I have a very simple unit test that just allocates a lot of Strings:
I have a very simple workflow that is just trying to send an email
I've been doing simple multi-threading in VB.NET for a while, and have just gotten
I'm now testing GKPeerPickerController. I have a simple app that just have a button
I'm trying to create a very simple REST server. I just have a test
I have a simple Django view that just returns URL parameters, but if I
I have a simple MVC 4 (Beta) Application and just observed something that I
Weird question, perhaps. We have a number of simple utilities written in-house that need
I have to develop a pretty simple php website so I don't need framework.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.