Skip to content

Possibility of multi-thread  #1

@soudazhou

Description

@soudazhou

Hi Latish,

Thanks a lot for your solution which does exactly what I need. I have noticed a slightly latency in the display of video on the UI during the recording, which I suppose could be solved by multi-thread. I have tried to use Backgroundworker Class to put the recording on a different thread than the UI, but got a error when I call bw.RunWorkerAsync(e); I will briefly explain my current solution below:

void KinectSensorAllFramesReady(object sender, AllFramesReadyEventArgs e)
{

        bw.RunWorkerAsync(e);
        //System.Console.WriteLine(" frame");
        using (var frame = e.OpenColorImageFrame())
        {

            if (frame != null)
            {
               // if (recorder != null)
               //     recorder.Record(frame);
                UpdateColorFrame(frame);
            }
        }

        using (var frame = e.OpenDepthImageFrame())
        {
            if (frame != null)
            {
                if (recorder != null)
                    recorder.Record(frame);
            }
        }

        using (var frame = e.OpenSkeletonFrame())
        {
            if (frame != null)
            {
                if (recorder != null)
                    recorder.Record(frame);
                UpdateSkeletons(frame);
            }
        }
    }

During the initialization, I declared a Backgroundworker object bw, and attached the eventhandler bw_DoWork o it, so it will record in another thread rather than the UI thread.

    private void bw_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;
        var arg = (AllFramesReadyEventArgs)e.Argument;
        var frame = (ColorImageFrame)arg.OpenColorImageFrame();
               if (frame != null)
            {
                if (recorder != null)
                    recorder.Record(frame);
            }
    } 

However, it will lead to "This BackgroundWorker is currently busy and cannot run multiple tasks concurrently." Which I suppose a new BackgroundWorker Object is needed for every frame?

Would be great if you could provide me some hints on how to put the recording on a separate thread so the color image display on the UI won't lag while recording, thanks.

Regards,

Wenxuan

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions