private void Window_Loaded(object sender, RoutedEventArgs e) { this.dataContext = new GhostDataContext(); //this.dataContext.DeleteDatabase(); //App.Current.Shutdown(); if (!dataContext.DatabaseExists()) { try { dataContext.CreateDatabase(); } catch (SqlException ex) { Console.WriteLine("EXCEPTION"); Console.WriteLine(ex.Message); Console.WriteLine("Deleting..."); try { dataContext.DeleteDatabase(); Console.WriteLine("Database deleted!"); } catch (SqlException ex2) { Console.WriteLine("Error deleting DB"); Console.WriteLine(ex2.Message); } App.Current.Shutdown(); } } this.savedSequences = dataContext.GhostSkeletonSequences.ToList(); foreach (KinectSensor potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (this.sensor != null) { this.sensor.ColorStream.Enable(); this.sensor.ColorFrameReady += sensor_ColorFrameReady; this.sensor.SkeletonStream.Enable(); this.sensor.SkeletonFrameReady += sensor_SkeletonFrameReady; // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // Allocate space to put the pixels we'll receive this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength]; // This is the bitmap we'll display on-screen this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgra32, null); // Display the drawing using our image control this.SkeletonImage.Source = this.imageSource; try { Console.WriteLine("Starting the sensor"); this.sensor.Start(); Console.WriteLine("Sensor started"); Timer timer = new Timer(3000); timer.Elapsed += timer_Elapsed; timer.Start(); } catch (IOException ex) { Console.WriteLine("Sensor start failed. " + ex.Message); this.sensor = null; } } else { MessageBox.Show("No Kinect detected. Please connect the Kinect and restart the program"); } }