void SaveImageRun() { //var accessToken = GetAccessToken(); //api = new DropboxApi(ConsumerKey, ConsumerSecret, accessToken); try { Stopwatch sw = new Stopwatch(); while (running) { sw.Start(); lock (images) { if (images.Count > 0) { PushImage item = images.First(); this.Dispatcher.Invoke((Action)(() => { if (item.Image != null) { this.Image = Ex.ToImage(item.Image); } })); if (OneFileMode) { string imageFile = "image.jpg"; string temp = "image_tmp.jpg"; SaveToDirectory(temp, item.Image); MoveToDirectory(temp, imageFile); } else { SaveToDirectory(item.Name, item.Image); } //var file = api.UploadFile2("dropbox\\imgTest", item.Name, item.Image); images.Remove(item); } } int frameTime = (int)(1000 / (double)FPS); int elapsed = (int)sw.ElapsedMilliseconds; if (elapsed < frameTime) { System.Threading.Thread.Sleep(frameTime - elapsed); } sw.Reset(); } } catch (ThreadInterruptedException) { // } catch (Exception ee) { MessageBox.Show("DropBox: " + ee.ToString()); running = false; } }
void saver_DoWork(object sender, DoWorkEventArgs e) { Stopwatch sw = new Stopwatch(); BackgroundWorker worker = (BackgroundWorker)sender; while (!worker.CancellationPending) { PushImage item = null; sw.Start(); lock (frameLock) { if (Frames.Count > 0) { item = Frames.Dequeue(); } } if (item != null) { if (OneFileMode) { string imageFile = "image.jpg"; string temp = "image_tmp.jpg"; SaveToDirectory(temp, item.Image); MoveToDirectory(temp, imageFile); } else { SaveToDirectory(item.Name, item.Image); //var file = api.UploadFile2("dropbox\\imgTest", item.Name, item.Image); } } int elapsed = (int)sw.ElapsedMilliseconds; int frameTime = (int)(1000 / (double)FPS); if (elapsed < frameTime) { System.Threading.Thread.Sleep(frameTime - elapsed); } sw.Reset(); } }