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

  • Home
  • SEARCH
  • 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 7816923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:03:05+00:00 2026-06-02T06:03:05+00:00

I have a .NET 4.0 ASP.NET project which requires some threading work I’ve never

  • 0

I have a .NET 4.0 ASP.NET project which requires some threading work I’ve never really messed with before and I’ve been looking at this for days and I’m still clueless =/

Basically I want something like when you take a ticket at the deli and wait your turn before they get back to you. I’ll try and relate this and see if it makes any sense…

function starts —> gets to section where it needs to “take a ticket” (I assume queue some type of item in a blockingcollection) and waits until other “tickets” (a.k.a other instances of the same function) are completed before it gives the function the OK to resume (blocking collection gets to the item in the queue) —> finish function.

I don’t need/want to do any work in the queue, I just want the function to statically wait it’s turn among other instances of the function. Does that make sense? Is that possible?

Please provide code if possible as I’ve seen tons of examples but none of them make sense/don’t do what I want.

  • 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-02T06:03:06+00:00Added an answer on June 2, 2026 at 6:03 am

    Alright so after researching document after document and playing with numerous rewrites of code I finally figured out I wasn’t using the AutoResetEvent right and how to use a blocking collection on a dedicated thread. So here was the final solution using an AutoResetEvent with a BlockingCollection. This solution below might not show the same results 100% of the time (just because I believe it has to do with thread timing of when something was entered into the blocking collection) but the end result is that it does exactly what I want.

    class Program
    {
        static void Main(string[] args)
        {
            TaskProcessor tp = new TaskProcessor();
    
            Thread t1 = new Thread(new ParameterizedThreadStart(tp.SubmitRequest));
            t1.Start(1);
    
            Thread t2 = new Thread(new ParameterizedThreadStart(tp.SubmitRequest));
            t2.Start(2);
    
            Thread t3 = new Thread(new ParameterizedThreadStart(tp.SubmitRequest));
            t3.Start(3);         
        }
    }
    
    class TaskProcessor
    {
        private AutoResetEvent _Ticket;
    
        public TaskProcessor()
        {
            _Continue = new AutoResetEvent(false);
        }
    
        public void SubmitRequest(object i)
        {
            TicketingQueue dt = new TicketingQueue();
    
            Console.WriteLine("Grab ticket for customer {0}", (int)i);
    
            dt.GrabTicket(_Ticket);
    
            _Continue.WaitOne();
    
            Console.WriteLine("Customer {0}'s turn", (int)i);
        }
    }
    
    public class TicketingQueue
    {
        private static BlockingCollection<AutoResetEvent> tickets = new BlockingCollection<AutoResetEvent>();
    
        static TicketingQueue()
        {
            var thread = new Thread(
              () =>
              {
                  while (true)
                  {                      
                      AutoResetEvent e = tickets.Take();
                      e.Set();
                      Thread.Sleep(1000);
                  }
              });
            thread.Start();
        }
    
        public void GrabTicket(AutoResetEvent e)
        {
            tickets.Add(e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET project which has already some custom fields in it's web.config
i have part of Asp.NET 1.1 project. I work with remote site, which works
I have a project (Web Application) which I have been developing in C#/ASP.NET, and
On a recent project I have been working on in C#/ASP.NET I have some
I have an ASP.NET project which is a front-end to a database. In addition
I have a Site.Master in my ASP.NET project which defines a HEAD section as
I have an ASP.NET web application project which references another project called ModusCore (or
I have a question I have a project asp.net mvc which is developed in
I have built a web setup project in VS2008 which installs my ASP.NET/Silverlight app
I have a master page in my asp.net MVC project, which has code like

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.