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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:33:51+00:00 2026-06-19T04:33:51+00:00

I have a web service which I need to ensure will finish processing then

  • 0

I have a web service which I need to ensure will finish processing then exit when onstop() is called. Currently when onstop() is called the service immediately stops. I’ve been told to look at ManualResetEvent and a requeststop flag. I’ve looked everywhere for examples even found a few of these:

How do I safely stop a C# .NET thread running in a Windows service?

To make a choice between ManualResetEvent or Thread.Sleep()

http://www.codeproject.com/Articles/19370/Windows-Services-Made-Simple

But I’ve having so much trouble understanding which one I can best apply to my situation.

Code below:

        System.Timers.Timer timer = new System.Timers.Timer();
        private volatile bool _requestStop = false;
        private static readonly string connStr = ConfigurationManager.ConnectionStrings["bedbankstandssConnectionString"].ConnectionString;
        private readonly ManualResetEvent _allDoneEvt = new ManualResetEvent(true);
        public InvService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            _requestStop = false;
            timer.Elapsed += timer_Elapsed;
            double pollingInterval = Convert.ToDouble(ConfigurationManager.AppSettings["PollingInterval"]);
            timer.Interval = pollingInterval;
            timer.Enabled = true;
            timer.Start();      
        }

        protected override void OnStop()
        {
            _requestStop = true;
            timer.Dispose();
        }

        protected override void OnContinue()
        { }

        protected override void OnPause()
        { }

        private void timer_Elapsed(object sender, EventArgs e)
        {
            if (!_requestStop)
            {
                timer.Start(); 
                InvProcessingChanges();     
            }               
        }

        private void InvProcessingChanges()
        { 
           //Processes changes to inventory
        }

Is anybody experienced with windows services there who can help me?
I’m quite new to windows services having just completed my first working service. This service needs to complete sending inventory updates before it actually stops.

  • 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-19T04:33:52+00:00Added an answer on June 19, 2026 at 4:33 am

    You an use something like ManualResetEvent to wait until the event enters a signalled state before completing Stop. ManualResetEventSlim might be more appropriate considering you’re trying to signal within the same process.

    Basically, you can call Wait on the event during the stop and while you’re processing call Reset and when you’re done, call Set.

    e.g.

    private ManualResetEventSlim resetEvent = new ManualResetEventSlim(false);
    
    public void InvProcessingChanges()
    {
        resetEventSlim.Reset();
        try
        {
            // TODO: *the* processing
        }
        finally
        {
            resetEvent.Set();
        }
    }
    
    public void WaitUntilProcessingComplete()
    {
        resetEvent.Wait();
    }
    

    and depending your your service:

        protected override void OnStop()
        {
            WaitUntilProcessingComplete();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WSDL 1.1 file which describes my Web Service. Now I need
I need to develop a WCF server (basically a web service which will eventually
I have created a web service in which i need to return multiple records
I have a web service which depending on the call executed I need different
I have a web service which access 2 other web services. I need to
I have the url to web service which returns some xml data. I need
I need to perform send photo functionality. I have a web service method which
Currently I have a web service, which loads up any plugins located within its
I have web service which i want to use to upload image to the
I have web service which return json string like : d={main0ID:abc.es/main,main1ID:ah/main} I wanna append

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.