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 3877122
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:27:40+00:00 2026-05-19T22:27:40+00:00

In my website, I am using a thread to perform a process in background.

  • 0

In my website, I am using a thread to perform a process in background. I start the thread on a button click.

Now the problem I face is that it seems to time out and stop. Basically it stops updating the database.

What could be wrong?

Here is my code:

 public static class BackgroundHelper 
 {
    private static readonly object _syncRoot = new object(); 
    private static readonly ManualResetEvent _event = new ManualResetEvent(false); 
    private static Thread _thread;
    public static bool Running 
    { 
        get; 
        private set;
    }
    public static void Start()
    {    
        lock (_syncRoot) 
        {
          if (Running)
                return; 
            Running = true;
            // Reset the event so we can use it to stop the thread.
            _event.Reset(); 
            // Star the background thread.
            _thread = new Thread(new ThreadStart(BackgroundProcess)); 
            _thread.Start();
        }
    }

    public static void Stop()   
    {
        lock (_syncRoot)
        {
            if (!Running)
                return;
            Running = false; 
            // Signal the thread to stop.
            _event.Set();
            // Wait for the thread to have stopped.
            _thread.Join(); 
            _thread = null;
        } 
    }   

    private static void BackgroundProcess()  
    { 
        int count = 0;
        DateTime date1 = new DateTime(2011, 2, 5);
        while (System.DateTime.Compare(System.DateTime.Now, date1) < 0)
        {
            downloadAndParse();  
            // Wait for the event to be set with a maximum of the timeout. The
            // timeout is used to pace the calls to downloadAndParse so that 
            // it not goes to 100% when there is nothing to download and parse.
            bool result = _event.WaitOne(TimeSpan.FromSeconds(45));
            // If the event was set, we're done processing.
           // if (result)
             //   break;
            count++; 
        }
    }

    private static void downloadAndParse()
    {
        NewHive.MyServ newServe = new NewHive.MyServ();
        NewHive.CsvDownload newService = new NewHive.CsvDownload();
        //NewHive.MyServ newServe = new NewHive.MyServ();
        string downloadSuccess = newService.CsvDownloader();
        if (downloadSuccess == "Success")
        {
            string parseSuccess = newService.CsvParser();

        }
        newServe.updateOthersInPosition();
    }
}
  • 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-05-19T22:27:41+00:00Added an answer on May 19, 2026 at 10:27 pm

    A background thread can only live as long as the thread that calls it is alive. Since the web server has a finite request/response lifecycle your background’s process can’t exceed this time limit. Once the timeout is reached on the web server, the server will generate the response (timeout), push it to the client and stop the thread. This event will kill your background thread, so if it’s mid-update on the database it’ll just stop. If you’re doing something like writing to a file, it’ll leave that file open, locked and improperly written (requiring a reboot to regain access to the corrupted file).

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

Sidebar

Related Questions

In my website, I am using thread to perform a repetitive process in background.
In my website I am using thread to perform the function which downloads the
I have developed a website using Razor (Microsoft WebMatrix) and now I want to
I am building a website using php and mysql.I have a login that is
I am creating a website using ASP.NET that supports multiple languages. For that I
I've a legacy application using Asp.Net WebSite (winforms...) and I need run a background
I have a website that allows users to query for specific recipes using various
I'm using acts_as_tree plugin for my user messaging thread feature on my website. I
I am using Selenium Grid with TestNG to test a website. The test-code, that
I have a process in a website (Asp.net 3.5 using Linq-to-Sql for data access)

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.