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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:40:32+00:00 2026-06-15T16:40:32+00:00

I need a operations which needs to run every x seconds forever, and to

  • 0

I need a operations which needs to run every x seconds forever, and to achieve this I did:

protected void Application_Start()
{
    InitialieOnce.Initialize();
}

public static class InitialieOnce
{
    private static bool initialized = false;

    public static void Initialize()
    {
        if (initialized == false)
        {
            initialized = true;
            Thread t = new Thread(x => CheckStatus());
            t.IsBackground = true;
            t.Start();
        }
    }

    private static void CheckStatus()
    {
        //My script goes here.
        Thread.Sleep(8000);
        CheckStatus();
    }
}

After some time (about 5 minutes) I get this error:

"An unhandled exception of type ‘System.StackOverflowException’ occurred in mscorlib.dll"

Can this error be related to how I made my infinite loop?

If yes, is there a better way to achieve this, can I fix it, or is this code ok?

  • 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-15T16:40:32+00:00Added an answer on June 15, 2026 at 4:40 pm

    You are calling “CheckStatus” recursively. So every 8 seconds there will be one more entry on your call stack:

    CheckStatus() -> CheckStatus() -> CheckStatus() -> and so on.. until you get a StackOverflowException.

    Instead you should use

    while (true)
    {
        /* Your Code */
        Thread.Sleep(8000);
    }
    

    Please also note that by default IIS will unload your application if there was no request in 15 minutes, resulting in your thread being killed.

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

Sidebar

Related Questions

I need a data structure which will support the following operations in a performant
I need to perform some operations on all folders within a file share which
i'm writing an installer using py2exe which needs to run in admin to have
I need a query which can do the following operation. I have a table
I am developing a firefox extension, i need to detect which operating system firefox
I need to perform operations on Lua tables from C where the tables are
I need to perform multiple operations on an Image, for example, I need to
I need to do some registry operations & other system operations for that i
I need to force any time related operations to GMT/UTC, regardless the timezone set
We need to profile the JDBC operations of several web applications, number of queries,

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.