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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:19:24+00:00 2026-06-15T17:19:24+00:00

i have a windows service that starts a timer on the main thread. The

  • 0

i have a windows service that starts a timer on the main thread. The timers job is to load an xml file to memory, do some processing on the values and save the results back to the file. The processing can take 10 minutes for example. (lets call this operation A)

I also have a thread that gets spawned via WCF on the same service which updates the xml file. (lets call this operation B)

What is happening is that Operation A is running and Operation B runs to completion before Operation A is completed. The end result being that operation A overwrites all the work that operation B completed.

So what i think i need to do is:

  1. When Operation A is starting,If operation B is running, wait for
    operation B to complete then execute Operation A

  2. When Operation B is started,If operation A is running, wait for
    operation A to complete then execute Operation B

if i could do this i wouldn’t have a problem i think.

I hope this makes sense –
Is my wait theory the best way to do this?
How can i do this in c# (or whatever the best method is)?

thanks
Damo

  • 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-15T17:19:25+00:00Added an answer on June 15, 2026 at 5:19 pm

    This is easily solved by using the lock statement in C#.

    All you’ll need is an instance of some object (the type doesn’t matter) that both sections of code have access to.

    public static void MethodA(object lockObject)
    {
        lock(lockObject)
        {
            //code that needs to be accessed by just one thread
        }
    }
    
    public static void MethodB(object lockObject)
    {
        lock(lockObject)
        {
            //code that needs to be accessed by just one thread
        }
    }
    

    If both of these operations are being fired from a timer you should ensure that adding extra waiting doesn’t push you to the point where executing the code takes longer than the interval on the timer; if you do you’ll end up firing off new code quicker than they finish and there will always be more and more instances running. (That is solved by having it do nothing if a previous task is still running.)

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

Sidebar

Related Questions

I have a windows service that does some intensive work every one minute (actually
I have a windows service that generates logs as it does some execution. I
I have a c# app (Windows Service) that fires a timer event that reads
I have a .NET Windows Service which spawns a thread that basically just acts
I have created a Windows Service that will be calling out to some COM
I have created a C# Windows Service application that starts a FileSystemWatcher to monitor
I have a windows Service that start some tasks based on a configuration. Each
I have a windows service that has a timer that fires a method every
I have a batch file that starts a Java process in a Windows 2003
Right, so I have a Windows service that goes off and does some work

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.