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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:43:44+00:00 2026-05-14T02:43:44+00:00

I am employing ThreadPool.QueueUserWorkItem to play some sound files and not hanging up the

  • 0

I am employing ThreadPool.QueueUserWorkItem to play some sound files and not hanging up the GUI while doing so.

It is working but has an undesirable side effect.

While the QueueUserWorkItem CallBack Proc is being executed there is nothing to stop it from starting a new thread. This causes the samples in the threads to overlap.

How can I make it so that it waits for the already running thread to finish running and only then run the next request?

EDIT: private object sync = new Object();
lock (sync) {
.......do sound here
}

this works. plays in the sounds in order.

but some samples are getting played more than once when i keep sending sound requests before the one being played ends. will investigate.

EDIT: is the above a result of Lock Convoy @Aaronaught mentioned?

  • 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-14T02:43:44+00:00Added an answer on May 14, 2026 at 2:43 am

    This is a classic thread synchronization issue, where you have multiple clients that all want to use the same resource and need to control how they access it. In this particular case, the sound system is willing to play more than one sound at the same time (and this is often desirable), but since you don’t want that behavior, you can use standard locking to gate access to the sound system:

    public static class SequentialSoundPlayer
    {
        private static Object _soundLock = new object();
    
        public static void PlaySound(Sound sound)
        {
            ThreadPool.QueueUserWorkItem(AsyncPlaySound, sound);
        }
    
        private static void AsyncPlaySound(Object state)
        {
            lock (_soundLock)
            {
                Sound sound = (Sound) state;
                //Execute your sound playing here...
            }
        }
    }
    

    where Sound is whatever object you’re using to represent a sound to be played. This mechanism is ‘first come, first served’ when multiple sounds vie for play time.


    As mentioned in another response, be careful of excessive ‘pile-up’ of sounds, as you’ll start to tie up the ThreadPool.

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

Sidebar

Related Questions

Not sure if this has a straightforward solution, but I want to write a
Been having some trouble implementing a single-column index in LaTeX. I've been employing the
I am working on a stylesheet employing many templates with match attributes: <xsl:template match=//one
Some background first. I'm employing the following trick to prevent undesired browser caching of
We have multiple developers working on a project. We're employing a feature-branch method of
I am currently employing a CAPTCHA technique which requires a visitor to rearrange some
I'm employing a custom webpart that is made by an unaffiliated third party. I've
I'm exploring Rails for the first time and trying to add some fairly straightforward
It seems so dirty emptying a list in this way: while len(alist) > 0
In employing Domain Driven design I often encounter an issue regarding the various perspective

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.