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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:08:27+00:00 2026-06-12T21:08:27+00:00

I am beginner to .NET. I have a question regarding windows service application running

  • 0

I am beginner to .NET.

I have a question regarding windows service application running multi-thread. My question is when I tried to register my application into windows service, I see my service status in “starting” in the service windows. I have included few lines code to show what I am trying to do.

protected override void OnStart(string [] args) {
    timer = Timer(5000);
    timer.Elapsed += new ElapsedEventHandler(OnElapsedTime); 
    timer.Start();

    // when I commented out Application.Run() it runs perfect.
    Application.Run(); // run until all the threads finished working
    //todo
}

private void OnElapsedTime(object s, ElapsedEventArgs e) {
    SmartThreadPool smartThreadPool = new SmartThreadPool();

    while( i < numOfRecords){
         smartThreadPool.QueueWorkItem(DoWork);
         //.....
    }
}

If you need further information please let me know.

  • 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-12T21:08:28+00:00Added an answer on June 12, 2026 at 9:08 pm

    Application.Run() in the context you’ve used it just tells the service to run itself again in the same application context. As a part of your Windows Service, an application context already exists within the context of your ServiceBase. Since it’s a service, it won’t stop until it’s given an instruction to stop through either a method that requires it, an unhandled exception or an external command.

    If you’re concerned about preventing the stop from occurring while threads are in the midst of executing, you’ll need a global lock of some sort indicating processes are working. It might be as simple as elevating the scope of your SmartThreadPool:

    private SmartThreadPool _pool = null;
    private SmartThreadPool Pool 
    {
        get
        {
            if (_pool == null)
                _pool = new SmartThreadPool();
            return _pool;
        }
    }
    
    protected override void OnStop()
    {
       if (Pool != null)
       {
           // Forces all threads to finish and 
           // achieve an idle state before 
           // shutting down
           Pool.WaitForIdle();
           Pool.Shutdown();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner with .NET environment. I have a windows application with three
This is a beginner level question for asp.net MVC I have the following code
Probably a very basic beginner question. Imagine the following situation: I have an ASP.NET
I have a beginner level Json question with MVC.net (I've never really used jquery
I'm a beginner in asp.net, and have a few question of Cache: HttpRuntime.Cache only
I have created a new Windows Forms Application with C# and .NET 4.0, and
I apologize for yet, another beginner question. I have a .Net background and this
I am just a beginner in ASP.NET. My question is simple, I wanna add
I have a small-scale WPF application using VB.net as the code behind and I
Ok so while back I asked question Beginner ASP.net question handling url link I

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.