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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:14:42+00:00 2026-06-12T15:14:42+00:00

I need to create a single class instance in web application that manage a

  • 0

I need to create a single class instance in web application that manage a queue of process. This class have multiple thread inside that look for queue and consume it.
What is the best why to do this?

I have apply singleton design pattern, but I don’t understand if have to create static or normal queue inside it. Some one can give me an example please?

SOLUTION

Ok thank you! This is my singleton class:

    public sealed class MyWorkingSingletonClass
    {

    private static readonly ILog LOG = LogManager.GetLogger(typeof(MyWorkingSingletonClass));
    private static MyWorkingSingletonClass instanza;
    private static readonly object lockObject = new object();
    private static ConcurrentQueue<Process> syncCoda = new ConcurrentQueue<Process>();

    private MyWorkingSingletonClass()
    {
    }

    public static MyWorkingSingletonClass Instanza
    {
        get
        {
            lock (lockObject)
            {
                if (instanza == null)
                    instanza = new PdfDucumentConverter();
                return instanza;
            }
        }
    }



    public void AddProcess(Process p)
    {
        syncCoda.Enqueue(p);
    }

    public void Start()
    {
        Task.Factory.StartNew(WorkerTask2);
    }

    public static void WorkerTask2()
    {

        do
        {
            try
            {
                Process p;
                if (syncCoda.TryDequeue(out p))
                {
                    p.Start();
                    p.PriorityClass = ProcessPriorityClass.High;
                    p.WaitForExit();
                }
            }
            catch (Exception ex)
            {
                LOG.Error(ex);
            }
        } while (true);
    }

    }
  • 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-12T15:14:43+00:00Added an answer on June 12, 2026 at 3:14 pm

    What you need is to implement new singleton class which inherits Concurrent Queue class which is thread-safe queue to ensure it will work in multi-thread environment:

    public class SingletonConcurrentQueue<T> : ConcurrentQueue<T>
    {
        private static readonly SingletonConcurrentQueue<T> 
                                       _instance = new SingletonConcurrentQueue<T>();
    
        static SingletonConcurrentQueue(){}
        private SingletonConcurrentQueue(){}
    
        public static SingletonConcurrentQueue<T> Instance
        {
            get { return _instance; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used the singleton pattern to create a single instance of a web
I need to create a single trace file that spans several days for one
For my application (an MMC snap-in) I need to create a single native DLL
I need to create an NSString that has a single random uppercase letter. I
Sometimes you need to create a very simple single file application in Qt4. However
i have a single video (duration: 3 seconds) and i need to create 2
I have a Singleton class to have only one single instance of my MPIProxy
I have a requirement to have a only a single instance of a class
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass
I have an interface that has about 20 methods (huge). I want to create

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.