private void _ThreadFunction() { try { _CheckForNodes(tlcServer.Nodes); } catch (Exception ex) { // do nothing because its our stupid thread Debug.WriteLine(ViException.ErrorString(ex)); } }
private void _ThreadFunction() { bool bExistsJobs; try { List <TreeListNode> lNodes = new List <TreeListNode> (tlcProfile.Nodes.Count); lock (tlcProfile.Nodes.SyncRoot) { foreach (TreeListNode tlnProfile in tlcProfile.Nodes) { lNodes.Add(tlnProfile); } } foreach (TreeListNode tlnProfile in lNodes) { NodeData nds = m_tlnServer.Tag as NodeData; NodeData ndp = tlnProfile.Tag as NodeData; bExistsJobs = JobQueueCheck.ExistsCopyJobs(ndp.Type, nds.Data1, ndp.Data1); tlnProfile.SubItems[5].Caption = bExistsJobs.ToString(); tlnProfile.ImageIndex = _GetPictureIndex(tlnProfile); } tlcProfile.Invalidate(); } catch (Exception ex) { // do nothing because its our stupid thread Debug.WriteLine(ViException.ErrorString(ex)); } }
private void _WriteIni() { string dir = Path.GetDirectoryName(_filename); dir = Path.Combine(dir, Guid.NewGuid().ToString()); // append the UID_Directory string tmpfile = Path.Combine(dir, Path.GetFileName(_filename)); IDictionary entries; // Create temp-directory on demand if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } AppData.Instance.RaiseMessage("ControlFilesComponent: Writing to " + tmpfile); try { // Store data using (StreamWriter writer = new StreamWriter(tmpfile, false, _encoding)) { writer.NewLine = "\r\n"; // Force windows line breaks foreach (DictionaryEntry section in _sections) { entries = section.Value as IDictionary; if (entries == null || entries.Count == 0) { continue; // Don't write empty sections } writer.WriteLine("[{0}]", section.Key); foreach (DictionaryEntry entry in entries) { if (entry.Value == null || entry.Value.ToString().Length == 0) { writer.WriteLine("{0}=\"\"", entry.Key); } else { writer.WriteLine("{0}={1}", entry.Key, entry.Value); } } writer.WriteLine(""); } writer.Flush(); } if (AppData.Instance.RuntimeEnvironment.IsMono) { // take rights from old to new file string parms = "-c 'getfacl \"" + _filename + "\" | setfacl --set-file=- \"" + tmpfile + "\"'"; // Old: chmod parameters //string cmd = "`stat -c %a \"" + _filename + "\"` \"" + tmpfile + "\""; try { AppData.Instance.RaiseMessage("ControlFilesComponent: Copying permissions from " + _filename + " to " + tmpfile); Process p = Process.Start("bash", parms); p.WaitForExit(); } catch (Exception ex) { AppData.Instance.RaiseMessage("ControlFilesComponent: Copying permissions failed with \"" + ex.Message + "\""); } } for (int i = 0; i < 5; i++) { try { AppData.Instance.RaiseMessage("ControlFilesComponent: Deleting " + _filename); File.Delete(_filename); AppData.Instance.RaiseMessage("ControlFilesComponent: Renaming " + tmpfile + " to " + _filename); File.Move(tmpfile, _filename); break; // No more retries } catch (IOException exc) { AppData.Instance.RaiseMessage("...failed with exception: " + ViException.ErrorString(exc)); if (i < 4) { AppData.Instance.RaiseMessage("Retry: " + (i + 1)); // stop thread for 100 to 500 milliseconds Thread.Sleep(new Random().Next(100, 500)); } else { AppData.Instance.RaiseMessage("Finally failed!"); // Remove temporary file File.Delete(tmpfile); throw; } } } } finally { try { if (File.Exists(tmpfile)) { File.Delete(tmpfile); } // Delete directory on demand if (Directory.Exists(dir)) { Directory.Delete(dir); } } catch (Exception ex) { AppData.Instance.RaiseMessage(MsgSeverity.Serious, "Error during cleanup: " + ex.Message); } } }