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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:00:12+00:00 2026-05-16T15:00:12+00:00

We have an implementation for an Ultrasound machine application current where the Ultrasound object

  • 0

We have an implementation for an Ultrasound machine application current where the Ultrasound object is created on the UI’s thread. A Singleton implementation would have been good here, but regardless, isn’t.

Recently, the set methods changed such that they automatically stop and restart the ultrasound machine, which can take between 10-100ms depending on the state of the machine. For most cases, this isn’t too bad of a problem, however it’s still causing the UI thread to block for 100ms. Additionally, these methods are not thread-safe and must be called on the same thread where the object was initialized.

This largest issue this is now causing is unresponsive buttons in the UI, especially sliders which may try to update variables many times as you slide the bar. As a result, sliders especially will stutter and update very slowly as it makes many set calls through databound propeties.

What is a good way to create a thread specifically for the creation and work for this Ultrasound object, which will persist through the lifetime of the application?

A current temporary workaround involves spawning a Timer, and invoking a parameter update once we have detected the slider hasn’t moved for 200ms, however a Timer would then have to be implemented for every slider and seems like a very messy solution which solves unresponsive sliders, but still blocks the UI thread occasionally.

  • 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-16T15:00:13+00:00Added an answer on May 16, 2026 at 3:00 pm

    One thing that’s really great about programming the GUI is that you don’t have to worry about multiple threads mucking things up for you (assuming you’ve got CheckForIllegalCrossThreadCalls = true, as you should). It’s all single-threaded, operating by means of a message pump (queue) that processes incoming messages one-by-one.

    Since you’ve indicated that you need to synchronize method calls that are not written to be thread-safe (totally understandable), there’s no reason you can’t implement your own message pump to deal with your Ultrasound object.

    A naive, very simplistic version might look something like this (the BlockingCollection<T> class is great if you’re on .NET 4.0 or have installed Rx extensions; otherwise, you can just use a plain vanilla Queue<T> and do your own locking). Warning: this is just a quick skeleton I’ve thrown together just now; I make no promises as to its robustness or even correctness.

    class MessagePump<T>
    {
        // In your case you would set this to your Ultrasound object.
        // You could just as easily design this class to be "object-agnostic";
        // but I think that coupling an instance to a specific object makes it clearer
        // what the purpose of the MessagePump<T> is.
        private T _obj;
    
        private BlockingCollection<Action<T>> _workItems;
        private Thread _thread;
    
        public MessagePump(T obj)
        {
            _obj = obj;
    
            // Note: the default underlying data store for a BlockingCollection<T>
            // is a FIFO ConcurrentQueue<T>, which is what we want.
            _workItems = new BlockingCollection<Action<T>>();
    
            _thread = new Thread(ProcessQueue);
            _thread.IsBackground = true;
            _thread.Start();
        }
    
        public void Submit(Action<T> workItem)
        {
            _workItems.Add(workItem);
        }
    
        private void ProcessQueue()
        {
            for (;;)
            {
                Action<T> workItem = _workItems.Take();
                try
                {
                    workItem(_obj);
                }
                catch
                {
                    // Put in some exception handling mechanism so that
                    // this thread is always running. One idea would be to
                    // raise an event containing the Exception object on a
                    // threadpool thread. You definitely don't want to raise
                    // the event from THIS thread, though, since then you
                    // could hit ANOTHER exception, which would defeat the
                    // purpose of this catch block.
                }
            }
        }
    }
    

    Then what would happen is: every time you want to interact with your Ultrasound object in some way, you do so through this message pump, by calling Submit and passing in some action that works with your Ultrasound object. The Ultrasound object then receives all messages sent to it synchronously (by which I mean, one at a time), while operating on its own non-GUI thread.

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

Sidebar

Related Questions

I was wondering if someone here have a good implementation of the Sieve of
Main menu in WP7 and audio player have the implementation. But how can i
I have an implementation of uploadify running on top of a PHP application. It
Does anyone have base32 implementation in Delphi? I found: http://cc.embarcadero.com/item/21566 but it is not
I have an implementation of a function called modify list shown below but it
I have this implementation file with a NSArray object userIDs NSArray *userIDs; NSInteger friendID;
I have an implementation messages system. My problem is, I would like to know
Have this implementation file which compiles and runs fine, but gives me an unused
I have this implementation, the result of this program is 100 but the correct
I downloaded the JSON2.js from https://github.com/douglascrockford/JSON-js/blob/master/json2.js and it does not have implementation for JSON2.stringify()

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.