// Thread entry point private void WorkerThread() { while (!stopEvent.WaitOne(0, true)) { // lock Monitor.Enter(this); int n = InnerList.Count; // check each camera for (int i = 0; i < n; i++) { Camera camera = (Camera)InnerList[i]; if (!camera.Running) { camera.CloseVideoSource(); InnerList.RemoveAt(i); i--; n--; } } // unlock Monitor.Exit(this); // sleep for a while Thread.Sleep(300); } // Exiting, so kill'em all foreach (Camera camera in InnerList) { camera.Stop(); } }
// Ensure the camera is stopped public void Remove(Camera camera) { // lock Monitor.Enter(this); int n = InnerList.Count; for (int i = 0; i < n; i++) { if (InnerList[i] == camera) { if (camera.Running) camera.Stop(); camera.CloseVideoSource(); InnerList.RemoveAt(i); break; } } // unlock Monitor.Exit(this); }
// Ensure the camera is stopped public void Remove(Camera camera) { // lock Monitor.Enter(this); int n = InnerList.Count; for (int i = 0; i < n; i++) { if (InnerList[i] == camera) { if (camera.Running) { camera.Stop(); } camera.CloseVideoSource(); InnerList.RemoveAt(i); break; } } // unlock Monitor.Exit(this); }