Software Archive
Read-only legacy content
17061 Discussions

Streaming Using Events In C#

Mike_J_
Beginner
274 Views

Can anyone get the example from the documentation  to work.

When I try it the OnNewSample is never called.  

 

 

pxcmStatus OnNewSample(Int32 mid, PXCMCapture.Sample sample) {

   if (sample.color!=null) {

       // work on the color sample

       ...

   }

   if (sample.depth!=null) {

       // work on the depth sample

       ...

   }

   // return NO_ERROR to continue, or any error to exit the loop

   return pxcmStatus.PXCM_STATUS_NO_ERROR;

};

 

void CaptureUnalignedColorDepthSamples() {

   PXCMSenseManager sm=PXCMSenseManager.CreateInstance();

 

   // select the color and depth streams

   sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR,640,480,30);

   sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH,320,240,30);

 

   // Initialize my handler

   PXCMSenseManager.Handler handler=new PXCMSenseManager.Handler();

   handler.onNewSample=OnNewSample;

   sm.Init(handler);

 

   // Streaming

   sm.StreamFrames(true);

 

   // Clean up

   sm.Dispose();

}

0 Kudos
1 Reply
Mike_J_
Beginner
274 Views

To make my question clearer - does the event handler approach work and if so why do none of the samples use it?

They all create a new thread and run the polling loop there which is what the event handler approach is supposed to do for you.

 

0 Kudos
Reply