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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:13:15+00:00 2026-05-28T14:13:15+00:00

here i have written a window service, it job is to read files from

  • 0

here i have written a window service, it job is to read files from one folder and sending the same content to database and sending readed files to some other folder

now my service having timer event has sets it was about of 10000 means ten seconds,
now if a process a files between 100 – 1000 ,with in 10 sec it was doing that job processing good output, case if process the files 6000 – 9000 at that particular situation my service is not producing exact out, it was not able to do that job in 10000 (ten seconds), so i need when service in middle of the job it should get interrupted since by timer completed but real scenario it should completed the particular job.

kindly give some suggestions, it would be appreciated

  • 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-28T14:13:15+00:00Added an answer on May 28, 2026 at 2:13 pm

    Different approaches that can work:

    1. Have the method called by the timer safe for re-entrance and then not worry about it. This tends to be either very easy to do (the task done is inherently re-entrant) or pretty tricky (if it’s not naturally re-entrant you have to consider the effects of multiple threads upon every single thing hit during the task).

    2. Have a lock in the operation, so different threads from different timer events just wait on each other. Note that you must know that there will not be several tasks in a row that take longer than the time interval, as otherwise you will have an ever-growing queue of threads waiting for their chance to run, and the amount of resources consumed just by waiting to do something will grown with it.

    3. Have the timer not set to have a recurring interval, but rather re-set it at the end of each task, so the next task will happen X seconds after the current one finishes.

    4. Have a lock and obtain it only if you don’t have to block. If you would have to block then a current task is still running, and we just let this time slot go by to stay out of it’s ways.

    After all, there’ll be another timer event along in 10 seconds:

    private static void TimerHandler(object state)
    {
      if(!Monitor.TryEnter(LockObject))
        return;//last timer still running
      try
      {
        //do useful stuff here.
      }
      finally
      {
        Monitor.Exit(LockObject);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my situation. I have written a WCF service which calls into one
I have written a service that monitors a file drop location for files from
I have an windows service that monitors a folder for new files being created.when
I've written a WCF service which tries to read the list items from a
I have written a code to read the value from many id's and display
I have a Windows service written in Delphi. One of the third-party resources it
Here is the code I have written for Rectangle class. class Rectangle (l: Double,
Well, i have written a simple python program that parses HTML with HTMLParser. Here
I have in here an old web application written in ASP.Net 2.0 + AJAX.
I have a menu written here which contains root elements and secondary elements. 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.