//chandle published file private void PublishWatcher_Changed(object sender, FileSystemEventArgs e) { //wait for file ready (event fire when WIN cc start writing file so I need to wait until he is done int checkCount = 0; while (IsFileLocked(e.FullPath)) { // log.Info("File stil locked"); System.Threading.Thread.Sleep(20); checkCount += 1; if (checkCount > 10) { log.Error("Was not able to acces file"); break; } } //handle file if available if (!IsFileLocked(e.FullPath)) { string Screenname = ""; try { //get file size System.Drawing.Image img = System.Drawing.Image.FromFile(e.FullPath); //match with table Screenname = (from Screens in configData.AsEnumerable() where Screens.Field <int>("height") == img.Height && Screens.Field <int>("width") == img.Width select Screens.Field <string>("screen")).ToList().First(); //dispose of img img.Dispose(); //push to network location try { string publishFullname = Path.Combine(tb_netExportLocation.Text, Screenname + ".jpg"); File.Copy(e.FullPath, publishFullname, true); //feedback info to screen log.Info("Published screen:" + Screenname); DataRow rowToUpdate = configData.AsEnumerable().Where(r => r.Field <string>("screen") == Screenname).First(); rowToUpdate.SetField("lastPublised", System.DateTime.Now.ToString()); } catch (Exception ex) { log.Error("Failed to copy file to net location", ex); //after a while password was always failing so need to remap the drive than ? //13:32:17,669[47] ERROR WebNavigator_Gadget_Watcher.WebNavigator_Gadget_Watcher_ConfigForm - Failed to copy file to net location System.IO.IOException: The user name or password is incorrect. log.Warn("try remapping drive"); map_drive(); } } catch (Exception ex) { log.Fatal("Failed to read image size", ex); //if something bad happens wait 10 seconds and restart. System.Threading.Thread.Sleep(10000); Environment.Exit(999); } } else { log.Error("did not handle file"); } }