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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:38:53+00:00 2026-05-13T09:38:53+00:00

I want to call a Business layer method from a Windows service (done using

  • 0

I want to call a Business layer method from a Windows service (done using C# and .NET) after every 10 seconds. However, i dont want to use the Timer_Elapsed event since it starts up another thread/process if the first thread/process is still running. I just need a single threaded approach, since multiple calls to the same Business method creates unwanted complications.

So i added a do–while loop in the on_start. I know this is not the correct way since it spawns this process which becomes an orphan if the service is shut down.

How can i approach this problem ?

Regards,
Chak

  • 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-13T09:38:53+00:00Added an answer on May 13, 2026 at 9:38 am

    There’s another way to get timed execution, the WaitHandle.WaitOne() method provides a timeout argument. That works very nicely in a service as it lets you implement the need to stop the service and periodic execution in a single method call. The template looks like this:

        Thread Worker;
        AutoResetEvent StopRequest = new AutoResetEvent(false);
    
        protected override void OnStart(string[] args) {
            // Start the worker thread
            Worker = new Thread(DoWork);
            Worker.Start();
        }
        protected override void OnStop() {
            // Signal worker to stop and wait until it does
            StopRequest.Set();
            Worker.Join();
        }
        private void DoWork(object arg) {
            // Worker thread loop
            for (;;) {
                // Run this code once every 10 seconds or stop right away if the service 
                // is stopped
                if (StopRequest.WaitOne(10000)) return;
                // Do work...
                //...
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to call a method say success(message) of javascript from android activity. I
When your domain layer or business layer (whatever you want to call it) is
I'd like to use EF directly in a business / service layer without using
I want to call a webservice using google closures, via jsonp since i am
i want to call the command prompt command using Process.Start and then using StandardOutput
I want to call a web service that requires an authentication cookie. I have
I want to call a method of my class inside a lambda expression: void
I try to create a JAVA EE application. In the business layer I want
We are using ASP.NET with a lot of AJAX Page Method calls. The WebServices
I have an object in my business layer (let's call it Car for example's

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.