private void myThreadStart() { System.Diagnostics.Debug.WriteLine("Entering thread proc"); int _i = 0; Intermec.Device.Sensor theSensor = new Intermec.Device.Sensor(Intermec.Device.Sensor.SensorsEnabled.AccelerometerEnabled); theSensor.SensorDataUpdateInterval = 50; ShakeDetection.GVector gv = new ShakeDetection.GVector(); try { do { //The blocking function... gv.X = theSensor.Acceleration.GForceX; gv.Y = theSensor.Acceleration.GForceY; gv.Z = theSensor.Acceleration.GForceZ; System.Diagnostics.Debug.WriteLine("Calling into UI thread..."); Microsoft.WindowsCE.Forms.Message msg = Message.Create(bgWnd.Hwnd, msgID, new IntPtr(_i), IntPtr.Zero); //to avoid reading and writing to var at same time from different threads lock (theLock) { _BGeventArgs._gvector = gv; //the PostMessage is catched in WndProc and the arguments are stored //retrived using the _BGeventArgs variable MessageWindow.PostMessage(ref msg); //hopefully there is no other posted msg } System.Diagnostics.Debug.WriteLine("Thread sleeps..."); _i++; Thread.Sleep(50); } while (bRunThread); } catch (ThreadAbortException) { System.Diagnostics.Debug.WriteLine("Thread will abort"); bRunThread = false; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception in ThreadStart: " + ex.Message); } System.Diagnostics.Debug.WriteLine("ThreadProc ended"); }
private void myThreadStart() { System.Diagnostics.Debug.WriteLine("Entering thread proc"); int _i=0; Intermec.Device.Sensor theSensor = new Intermec.Device.Sensor(Intermec.Device.Sensor.SensorsEnabled.AccelerometerEnabled); theSensor.SensorDataUpdateInterval = 50; ShakeDetection.GVector gv = new ShakeDetection.GVector(); try { do { //The blocking function... gv.X = theSensor.Acceleration.GForceX; gv.Y = theSensor.Acceleration.GForceY; gv.Z = theSensor.Acceleration.GForceZ; System.Diagnostics.Debug.WriteLine("Calling into UI thread..."); Microsoft.WindowsCE.Forms.Message msg = Message.Create(bgWnd.Hwnd, msgID, new IntPtr(_i), IntPtr.Zero); //to avoid reading and writing to var at same time from different threads lock (theLock) { _BGeventArgs._gvector = gv; //the PostMessage is catched in WndProc and the arguments are stored //retrived using the _BGeventArgs variable MessageWindow.PostMessage(ref msg); //hopefully there is no other posted msg } System.Diagnostics.Debug.WriteLine("Thread sleeps..."); _i++; Thread.Sleep(50); } while (bRunThread); } catch (ThreadAbortException) { System.Diagnostics.Debug.WriteLine("Thread will abort"); bRunThread = false; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception in ThreadStart: " + ex.Message); } System.Diagnostics.Debug.WriteLine("ThreadProc ended"); }