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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:49:00+00:00 2026-06-02T03:49:00+00:00

I know there is a better way to do this. I’m fairly new to

  • 0

I know there is a better way to do this. I’m fairly new to multithreaded programming, however raising my event on a new thread like the code below allows my application to get a higher FPS with the Kinect.

When the object of my KinectService class is initalized, inside that method I do this:

Thread t = new Thread(() =>
{
    sensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(sensor_AllFramesReady);
    KinectSensor.KinectSensors.StatusChanged += new    EventHandler<StatusChangedEventArgs>(Kinects_StatusChanged);
});
t.Start();

Which in turn calls this method:

void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) 
{
    using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
    {
        if (depthFrame == null)
        {
            return;
        }

        byte[] pixels = GenerateColoredBytes(depthFrame);            
        int stride = depthFrame.Width * 4;
        BitmapSource test = BitmapSource.Create(depthFrame.Width, depthFrame.Height,
                    96, 96, PixelFormats.Bgr32, null, pixels, stride);

        test.Freeze();

        if (FrameChanged != null)
        {
            FrameChanged(test);
        }
    }    
}

FrameChanged(test) passes the newly created bitmap back to the viewmodel which then updates the source of an image. Is this a terrible way to do this? Giving an event it’s own thread feels wrong, however it makes my application run a lot faster. Any pointers?

  • 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-02T03:49:01+00:00Added an answer on June 2, 2026 at 3:49 am

    Events are fired on the same thread that called them, and there isn’t anything in the documentation for KinectSensor.AllFramesReady to say otherwise.

    So in your code sensor.AllFramesReady won’t fire another event until your event handler (sensor_AllFramesReady) returns.

    A better way to do it possibly is to change your event handler to spawn off a thread and immediately return. I.e.

    void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)  
    {
        var frameReadyThread = new Thread(() =>
        using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) 
        {
            //
        }
        frameReadyThread.Start();
    }
    

    You will need to do some synchronisation though within frameReadyThread to ensure that the following is true,

    1. Frames are not handled out of order, you don’t want Frame 1 to update after Frame 2
    2. Frames are abandoned when they are no longer doing useful work rather than steal CPU.
    3. If you’re implementing your own thread dispatcher, that you scale appropriately to the machine you are on. For example, if you have access to 8 cores, and your handler code is CPU bound, its unlikely that you’ll see any benefit if you have more than 8 threads.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Git, so let me know if there is a better way
I know there's a better way to do this, but I don't know what
I know there has to be a better way to do this. Currently I
Don't know if there is a better way to do this, so that is
Notice the nested subqueries. I know there's a better way to make this happen
All, I would like to know if there is a better way of getting
I want to know if there is a better way (than what I'm currently
Is there a better way to do this: perms = product(range(1,7),range(1,7),range(1,7)) so that I
I would like to know is there a CSS like way to style child
I would like to know if there is any way to compare two Outlook.MailItem

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.