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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:43:33+00:00 2026-05-13T07:43:33+00:00

I am writing a ASP.NET queue processor. Users will login and upload data files

  • 0

I am writing a ASP.NET queue processor. Users will login and upload data files to the site, and then click to start processing the data files.

I have a Windows Service on the system that waits for items to arrive in the queue and processes them. So far everything works except the items in the queue seem to get lost. I believe the static members are losing scope, but I’m not sure how to fix it.

I thought about writing things to/from files, but the Status updates so often it would be a performance killer.

What’s the best way to get data in and out of the service?

The Windows service is as follows:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ServiceProcess;
using System.Threading;
using System.Timers;

namespace MyMonitorService
{
    public class MyMonitor : ServiceBase
    {
        #region Members
        private System.Timers.Timer timer = new System.Timers.Timer();
        private static Queue<String> qProjectQueue = new Queue<String>();
        private static Mutex mutexProjectQueue = new Mutex(false);
        private Boolean bNotDoneYet = false;
        #endregion

        #region Properties
        public static String Status { get; private set; }
        #endregion

        #region Construction
        public MyMonitor ()
        {
            this.timer.Interval = 10000; // set for 10 seconds
            this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);

            Status = String.Empty;
        }
        #endregion

        private void timer_Elapsed (object sender, ElapsedEventArgs e)
        {
            try
            {
                if (!this.bNotDoneYet)
                {
                    this.bNotDoneYet = true;
                    for (;;)
                    {
                        MyMonitor.mutexProjectQueue.WaitOne();
                        if (MyMonitor.qProjectQueue.Count == 0)
                        {
                            EventLog.WriteEntry("MyMonitor", "The queue is empty", EventLogEntryType.Information);
                            break;
                        }
                        String strProject = MyMonitor.qProjectQueue.Dequeue();
                        EventLog.WriteEntry("MyMonitor", String.Format("The project {0} was dequeued", strProject), EventLogEntryType.Information);
                        MyMonitor.mutexProjectQueue.ReleaseMutex();

                        // Do something that updates MyMonitor.Status up to thousands of times per minute
                    }
                }
                this.bNotDoneYet = false;
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("MyMonitor", ex.Message, EventLogEntryType.Error);
            }
        }

        public static void EnqueueProjects (params String[] astrProjects)
        {
            try
            {
                String strMessage = String.Format("The following projects were added to the queue:\n{0}", String.Join("\n", astrProjects));
                EventLog.WriteEntry("MyMonitor", strMessage, EventLogEntryType.Information);

                if (astrProjects == null)
                    return;

                MyMonitor.mutexProjectQueue.WaitOne();

                foreach (String strProject in astrProjects)
                    MyMonitor.qProjectQueue.Enqueue(strProject);

                MyMonitor.mutexProjectQueue.ReleaseMutex();
            }
            catch (Exception e)
            {
                EventLog.WriteEntry("MyMonitor", e.Message, EventLogEntryType.Error);
            }
        }

        #region Service Start/Stop
        [STAThread]
        public static void Main ()
        {
            ServiceBase.Run(new MyMonitor());
        }

        protected override void OnStart (string[] args)
        {
            try
            {
                EventLog.WriteEntry("MyMonitor", "MyMonitor Service Started", EventLogEntryType.Information);
                this.timer.Enabled = true;
            }
            catch (Exception e)
            {
                EventLog.WriteEntry("MyMonitor", e.Message, EventLogEntryType.Error);
            }
        }

        protected override void OnStop ()
        {
            try
            {
                EventLog.WriteEntry("MyMonitor", "MyMonitor Service Stopped", EventLogEntryType.Information);
                this.timer.Enabled = false;
            }
            catch (Exception e)
            {
                EventLog.WriteEntry("MyMonitor", e.Message, EventLogEntryType.Error);
            }
        }
        #endregion
    }
}
  • 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-13T07:43:34+00:00Added an answer on May 13, 2026 at 7:43 am

    Answering the general question how this could be solved (still unsure about the code at hand):

    Depends on your requirements. From “easy” to “high-end”:

    • File system entries (with watcher or polling)
    • Windows messages, SendMessage/PostMessage
    • A shared database layer
    • Message Queues (MS MQ for example)

    Regarding your code:

    First thought that crosses my mind: If the queue happens to be empty once you’ll break out of the timer event and the bNotDoneYet is never reset to false -> New entries wouldn’t be considered?

    In addition your producer/consumer pattern seems off for me. I’m used to a lightweight (and simplified):

    Producer:

    lock (_syncRoot) {
      _queue.Enqueue(obj);
      if (_queue.Count == 1) Monitor.Pulse(_syncRoot);
    }
    

    Consumer:

    lock (_syncRoot) {
      while (_queue.Count < 1) {
        try {
          Monitor.Wait(_syncRoot);
        } catch (ThreadInterruptedException) {}
      }
      var obj = _queue.Dequeue();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I came across the following blog that explains the nature… May 14, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer A DataGridView, when given a DataSource is inherently data-bound. You… May 14, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer I'll answer your last question first: a class is an… May 14, 2026 at 5:10 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.