public void ProcessPicture(Pulse.Base.PictureBatch pb, string config) { List<Picture> lp = pb.GetPictures(1); if (!lp.Any()) return; Picture p = lp.First(); ManualResetEvent mre = new ManualResetEvent(false); int stepCount = 13; //get color to start with Color currentAero = Desktop.GetCurrentAeroColor(); Color endAeroColor; //load file using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(p.LocalPath))) { using (Bitmap bmp = (Bitmap)Bitmap.FromStream(ms)) { //get final color endAeroColor = PictureManager.CalcAverageColor(bmp); } } //build transition Color[] transitionColors = CalcColorTransition(currentAero, endAeroColor, stepCount); //build timer System.Timers.Timer t = new System.Timers.Timer(100); int currentStep = 0; t.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e) { //double check (I've seen cases where timer fires even though currentStep is past {stepCount} if (currentStep >= stepCount) { mre.Set(); t.Stop(); return; } //set to next color Desktop.SetAeroColor(transitionColors[currentStep]); //increment steps and check if we should stop the timer currentStep++; if (currentStep >= stepCount) { mre.Set(); t.Stop(); } }; t.Start(); mre.WaitOne(); }