private void updateColor(object obj) { while (true) { AmbientLightControl control = (AmbientLightControl)obj; BasicColor color = control.color; this.startTicks = DateTime.Now.Ticks; // measure time color.Set(ScreenColor.GetAverageScreenColor(ScreenColor.DeterminationMethod.Partly)); // read screen color double factor = saturation; transferFunctionFactor = TransferFunction(color.GetDelta()); if (preventFlickering) { factor *= transferFunctionFactor; } control.outputColor = ColorManipulation.IncreaseSaturation(color, factor).Multiply(brightness); try { SerialCommunication.SendColor(control.outputColor); // update hardware this.error = null; } catch (Exception e) { this.error = e; } this.executionTime = DateTime.Now.Ticks - this.startTicks; // stop time measurement this.updateUI(); // update ui switch (this.updateSpeed) { case UpdateSpeed.Low: Thread.Sleep(400); // keep Windows very responsive break; case UpdateSpeed.Normal: Thread.Sleep(100); break; case UpdateSpeed.Maximum: // continue as quick as possible break; default: Thread.Sleep(100); break; } } }
public MainWindow() { InitializeComponent(); control = new AmbientLightControl(this); refreshPortList(); System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon(); notifyIcon.Visible = true; Stream iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/AmbientLight;component/Icon.ico")).Stream; notifyIcon.Icon = new System.Drawing.Icon(iconStream); notifyIcon.DoubleClick += delegate(object sender, EventArgs args) { this.Show(); this.WindowState = WindowState.Normal; }; }