static void Main() { bool tryCreateNewApp; mInstance = new System.Threading.Mutex(true, mAppName, out tryCreateNewApp); if (!tryCreateNewApp) { MessageBox.Show("The program has been already started."); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Application.Run(new EditorForm()); } catch (Exception ex) { //Log.LogMessage(ex); //string message = "Send log file to developers for fixing problem.\r\nThe program will be closed."; //Log.LogMessage(message); //mInstance.ReleaseMutex(); mInstance.Close(); mInstance.Dispose(); new ErrorRestart(KeyProgram.eDoctrinaOcrEd).ReStart(ex); } }
private string EncodeDecodeKey(string str, string param) {//Calls KeyCrypt with either -e or -d as a parameter and gets a string back and forth string encDecKey; using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("EncDecString", 80)) { System.Threading.Mutex mutex = new System.Threading.Mutex(true, "EncMemShare"); using (MemoryMappedViewStream stream = mmf.CreateViewStream()) { System.IO.StreamWriter wtr = new System.IO.StreamWriter(stream); wtr.Write(str); wtr.Flush(); } mutex.ReleaseMutex(); string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); path = System.IO.Path.GetDirectoryName(path); //now path is path to current executing assembly which is where KeyCrypt will be on install string keyCryptPath = System.IO.Path.Combine(path, "KeyCrypt.exe"); Process p = Process.Start(keyCryptPath, param); p.WaitForExit(); mutex.WaitOne(); //this process now waits until gets mutex back which means encryption is done //Console.ReadKey(); //wait to do pkencrypt using (MemoryMappedViewStream stream = mmf.CreateViewStream()) { System.IO.StreamReader rdr = new System.IO.StreamReader(stream); encDecKey = rdr.ReadToEnd(); encDecKey = encDecKey.Substring(0, encDecKey.IndexOf("\0")); } mutex.ReleaseMutex(); mutex.Dispose(); } return(encDecKey); }
protected virtual void Dispose(bool disposing) { if (disposing) { _outputMutex.Dispose(); _outputMutex = null; } }
private void ButtonInstall_Click(object sender, EventArgs e) { bool createdNew, success = false; var mutex = new System.Threading.Mutex(true, "XRmonitorsUIUnique", out createdNew); if (mutex != null) { mutex.Dispose(); mutex = null; success = true; } if (!success || !createdNew) { MessageBox.Show("An instance of XRmonitorsUI.exe is still running. \n\nClose the software before reinstalling it.", "XRmonitors - Still Running"); return; } try { string dir = textInstallPath.Text; if (dir.Length == 0) { return; } Directory.CreateDirectory(dir); } catch (Exception ex) { MessageBox.Show("Failed to create directory. Error: " + ex.ToString(), "XRmonitors - Directory Creation Failed", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } Program.InstallPath = textInstallPath.Text; // Enable auto-start try { if (checkAutoStart.Checked) { Console.WriteLine("Adding startup regkey"); string path = Path.Combine(Program.InstallPath, "XRmonitorsUI.exe"); Console.WriteLine("Found exe path: " + path); Program.AddStartup("XRmonitors", path); } } catch (Exception ex) { MessageBox.Show("Failed to set up AutoStart: ", ex.ToString()); checkAutoStart.Enabled = false; } Program.setup_form.progress_panel.Show(); this.Hide(); Program.setup_form.progress_panel.Install(); }
/// <summary> /// /// </summary> private void Dispose() { if (Reading) { StopRead(); } hidHandle.Close(); _MutexPTT.Dispose(); }
/// <summary> /// 是否互斥 true 是不存在互斥 false是互斥 /// </summary> /// <returns></returns> public bool GetMutexFlag() { if (this.Value == null) { return(false); } mutex?.Dispose(); mutex = new System.Threading.Mutex(true, this.Value, out bool ret); return(ret); }
/// <summary> /// Disposable pattern /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { ReleaseUnmanagedResources(); if (disposing) { _udpClient?.Dispose(); _mutex?.Dispose(); _receivedPackets?.Clear(); } }
protected override void Dispose(bool disposing) { try { _mutex.Dispose(); } finally { base.Dispose(disposing); } }
private void Dispose(bool disposing) { ReleaseUnmanagedResources(); if (disposing) { Terminate(); _logMutex?.Dispose(); _deviceMutex?.Dispose(); _timer?.Dispose(); } }
public static void Dispose() { if (_Mutex != null) { _Mutex.Dispose(); } if (_ResumeTimer != null) { _ResumeTimer.Dispose(); } }
public void Dispose() { try { _mutex.ReleaseMutex(); _mutex.Dispose(); // _mutex.Close(); .NET Standard 2.0 } catch { } }
/// <summary> /// Clean up any /// being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { if (_Mutex != null) { _Mutex.Dispose(); } Manager.Dispose(); Manager = null; components.Dispose(); } base.Dispose(disposing); }
public static void Run() { var mutex = new System.Threading.Mutex(false, "MyApp ver 2.0"); if (!mutex.WaitOne(TimeSpan.FromSeconds(5), false)) { Console.WriteLine("Other instanse is running"); Console.ReadLine(); return; } Console.WriteLine("Welcome to MyApp ver 2.0"); Console.ReadLine(); mutex.Dispose(); }
private static bool SingleInstanceCheck() { for (int i = 0; i < MutexAttempts; i++) { if (!GetMutex()) { // Dispose the mutex, otherwise it will never create new _retroBarMutex.Dispose(); System.Threading.Thread.Sleep(MutexWaitMs); } else { return(true); } } return(false); }
private void Button_Click(object sender, RoutedEventArgs e) { xml_data.Document.Blocks.Clear(); string file = filename_edit.Text; bool timeout = false; bool initial_owned; System.Threading.Mutex shm_mutex = new System.Threading.Mutex(true, "Global\\" + file + "_mutex", out initial_owned); if (!initial_owned) { bool mutex_is_free = shm_mutex.WaitOne(50); if (mutex_is_free == false) { timeout = true; return; } } else { shm_mutex.ReleaseMutex(); shm_mutex.Dispose(); return; } if (timeout) { return; } string text_xml = ""; using (var shm = System.IO.MemoryMappedFiles.MemoryMappedFile.OpenExisting(file, System.IO.MemoryMappedFiles.MemoryMappedFileRights.Read)) { using (var read_stream = shm.CreateViewStream(0, 0, System.IO.MemoryMappedFiles.MemoryMappedFileAccess.Read)) { System.IO.StreamReader reader = new System.IO.StreamReader(read_stream); text_xml = reader.ReadToEnd(); text_xml = text_xml.Trim('\0'); } } shm_mutex.ReleaseMutex(); xml_data.Document.Blocks.Add(new Paragraph(new Run(text_xml))); }
static void Main() { bool createNew; System.Threading.Mutex appMutex = new System.Threading.Mutex( true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out createNew); if (createNew) { loadedAssembly = new Dictionary <string, Assembly>(); AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad; AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); new Main().run(); } appMutex.Dispose(); }
private void Button_Click(object sender, RoutedEventArgs e) { xml_data.Document.Blocks.Clear(); string file = filename_edit.Text; bool timeout = false; bool initial_owned; System.Threading.Mutex shm_mutex = new System.Threading.Mutex(true, "Global\\" + file + "_mutex", out initial_owned); if (!initial_owned) { bool mutex_is_free = shm_mutex.WaitOne(50); if (mutex_is_free == false) { timeout = true; return; } } else { shm_mutex.ReleaseMutex(); shm_mutex.Dispose(); return; } if (timeout) return; string text_xml = ""; using (var shm = System.IO.MemoryMappedFiles.MemoryMappedFile.OpenExisting(file, System.IO.MemoryMappedFiles.MemoryMappedFileRights.Read)) { using (var read_stream = shm.CreateViewStream(0,0, System.IO.MemoryMappedFiles.MemoryMappedFileAccess.Read)) { System.IO.StreamReader reader = new System.IO.StreamReader(read_stream); text_xml = reader.ReadToEnd(); text_xml = text_xml.Trim('\0'); } } shm_mutex.ReleaseMutex(); xml_data.Document.Blocks.Add(new Paragraph(new Run(text_xml))); }
private void ButtonRemove_Click(object sender, EventArgs e) { bool createdNew, success = false; var mutex = new System.Threading.Mutex(true, "XRmonitorsUIUnique", out createdNew); if (mutex != null) { mutex.Dispose(); mutex = null; success = true; } if (!success || !createdNew) { MessageBox.Show("An instance of XRmonitorsUI.exe is still running. \n\nClose the software before removing it.", "XRmonitors - Still Running"); return; } Program.setup_form.remove_progress_panel.Show(); this.Hide(); Program.setup_form.remove_progress_panel.Remove(); }
/// <summary> /// free all used ressources, /// abort all work /// </summary> public void stop_instance() { //delete old mutex bool initial_owned; System.Threading.Mutex shm_mutex = new System.Threading.Mutex(true, "Global\\" + export_name + "_mutex", out initial_owned); if (!initial_owned) { shm_mutex.WaitOne(250); } if (memory_file != null && memory_file.SafeMemoryMappedFileHandle.IsInvalid != true) { memory_file.Dispose(); } memory_file = null; shm_mutex.ReleaseMutex(); shm_mutex.Dispose(); shm_mutex = null; memory_file_size = 0; _in_progress = false; }
/// <summary> /// free all used ressources, /// abort all work /// </summary> public void stop_instance() { //delete old mutex bool initial_owned; System.Threading.Mutex shm_mutex = new System.Threading.Mutex(true, "Global\\" + export_name + "_mutex", out initial_owned); if (!initial_owned) { shm_mutex.WaitOne(250); } if (memory_file != null && memory_file.SafeMemoryMappedFileHandle.IsInvalid != true) memory_file.Dispose(); memory_file = null; shm_mutex.ReleaseMutex(); shm_mutex.Dispose(); shm_mutex = null; memory_file_size = 0; _in_progress = false; }
/// <summary> /// Call this within a transaction. /// </summary> /// <param name="originalSubject"></param> /// <param name="singleFco"></param> /// <param name="OutputSubDir"></param> public void UpdateResultsJson( MgaFCO singleFco, string OutputSubDir) { string jsonFile = Path.Combine(this.GetResultsFolder(), "results.metaresults.json"); AVM.DDP.MetaResults results = null; bool createdNew; using (System.Threading.Mutex jsonFileMutex = new System.Threading.Mutex(false, "results_metaresults_mutex", out createdNew)) { jsonFileMutex.WaitOne(); try { if (File.Exists(jsonFile)) { string content = ""; using (StreamReader reader = new StreamReader(jsonFile)) { content = reader.ReadToEnd(); } try { results = JsonConvert.DeserializeObject<AVM.DDP.MetaResults>(content); } catch (Newtonsoft.Json.JsonReaderException ex) { // Will this cause problems if we run it from the job manager??? Should we only log it istead? throw new Exception(string.Format("{0} file is probably malformed. Not a valid json. {1}{2}", Path.GetFullPath(jsonFile), Environment.NewLine, ex.Message)); } // TODO: remove broken links } else { results = new AVM.DDP.MetaResults(); } AVM.DDP.MetaResults.Result thisResult = new AVM.DDP.MetaResults.Result(); thisResult.Summary = MakeRelativePath( Path.GetDirectoryName(jsonFile), Path.Combine(OutputSubDir, AVM.DDP.MetaTBManifest.TESTBENCH_FILENAME)).Replace('\\', '/'); thisResult.Time = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"); thisResult.TestBench = singleFco.RegistryValue["TestBenchUniqueName"] + ".testbench.json"; Func<MgaFCO, CyPhy.TestBenchType> cast; if (TestbenchAndCompositeTypes.TryGetValue(singleFco.Meta.Name, out cast)) { CyPhy.TestBenchType testBench = cast(singleFco); var tlsut = testBench.Children.TopLevelSystemUnderTestCollection.FirstOrDefault(); if (tlsut != null) { if (tlsut.AllReferred is CyPhy.ComponentAssembly) { var cfg = tlsut.Referred.ComponentAssembly; var cid = cfg.Attributes.ConfigurationUniqueID; //this.ConfigurationUniqueID = cid; if (string.IsNullOrWhiteSpace(cid)) { cid = Guid.NewGuid().ToString("B"); cfg.Attributes.ConfigurationUniqueID = cid; } if (!string.IsNullOrEmpty(cid)) { try { Guid guid = new Guid(cid); thisResult.DesignID = guid.ToString("B"); } catch (System.FormatException ex) { Trace.TraceError("{0} is not a vaild GUID.", cid); Trace.TraceError(ex.ToString()); } } } } } results.Results.Add(thisResult); var dirname = Path.GetDirectoryName(jsonFile); if (Directory.Exists(dirname) == false) { Directory.CreateDirectory(dirname); } using (StreamWriter writer = new StreamWriter(jsonFile)) { writer.WriteLine(JsonConvert.SerializeObject(results, Newtonsoft.Json.Formatting.Indented)); } } finally { jsonFileMutex.ReleaseMutex(); jsonFileMutex.Dispose(); } } }
private void GenerateDashboardScriptFiles() { if (this.ProjectManifest == null) { throw new InvalidOperationException(); } var mutex = new System.Threading.Mutex(false, "OpenMETA_CyPhyMasterInterpreter_dashboard"); mutex.WaitOne(); try { // Generate python scripts if not already there string export_for_dashboard_scoring = Path.GetFullPath( Path.Combine(this.ProjectManifest.OutputDirectory, "export_for_dashboard_scoring.py")); if (File.Exists(export_for_dashboard_scoring) == false) { using (StreamWriter writer = new StreamWriter(export_for_dashboard_scoring)) { writer.WriteLine(Properties.Resources.export_for_dashboard_scoring); } } // Check if the "stats" directory exists; if not, make it string stat_dir_path = Path.GetFullPath( Path.Combine(this.ProjectManifest.OutputDirectory, "stats")); if (Directory.Exists(stat_dir_path) == false) { Directory.CreateDirectory(stat_dir_path); } string gather_stat_json = Path.GetFullPath( Path.Combine(stat_dir_path, "gather_stat_json.py")); if (File.Exists(gather_stat_json)) { File.Delete(gather_stat_json); } using (StreamWriter writer = new StreamWriter(gather_stat_json)) { writer.WriteLine(Properties.Resources.gather_stat_json); } // Check if the "log" folder exists; if not, create it string log_folder_path = Path.GetFullPath( Path.Combine(this.ProjectManifest.OutputDirectory, "log")); if (Directory.Exists(log_folder_path) == false) { Directory.CreateDirectory(log_folder_path); } string gather_all_logfiles = Path.GetFullPath( Path.Combine(log_folder_path, "gather_all_logfiles.py")); if (File.Exists(gather_all_logfiles)) { File.Delete(gather_all_logfiles); } using (StreamWriter writer = new StreamWriter(gather_all_logfiles)) { writer.WriteLine(Properties.Resources.gather_all_logfiles); } index_html index = new index_html(); index.ProjectName = Path.GetFileNameWithoutExtension(this.ProjectManifest.Project.CyPhyProjectFileName); index.AvmProjectFileName = Path.GetFileName(this.ProjectManifest.m_filename); string indexFileName = this.GetIndexFilename(); using (StreamWriter writer = new StreamWriter(indexFileName)) { string index_content = index.TransformText(); writer.WriteLine(index_content); } } finally { mutex.ReleaseMutex(); mutex.Dispose(); } }
private string EncodeDecodeKey(string str, string param) { //Calls KeyCrypt with either -e or -d as a parameter and gets a string back and forth string encDecKey; using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew("EncDecString", 80)) { System.Threading.Mutex mutex = new System.Threading.Mutex(true, "EncMemShare"); using (MemoryMappedViewStream stream = mmf.CreateViewStream()) { System.IO.StreamWriter wtr = new System.IO.StreamWriter(stream); wtr.Write(str); wtr.Flush(); } mutex.ReleaseMutex(); string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); path = System.IO.Path.GetDirectoryName(path); //now path is path to current executing assembly which is where KeyCrypt will be on install string keyCryptPath = System.IO.Path.Combine(path, "KeyCrypt.exe"); Process p = Process.Start(keyCryptPath, param); p.WaitForExit(); mutex.WaitOne(); //this process now waits until gets mutex back which means encryption is done //Console.ReadKey(); //wait to do pkencrypt using (MemoryMappedViewStream stream = mmf.CreateViewStream()) { System.IO.StreamReader rdr = new System.IO.StreamReader(stream); encDecKey = rdr.ReadToEnd(); encDecKey = encDecKey.Substring(0, encDecKey.IndexOf("\0")); } mutex.ReleaseMutex(); mutex.Dispose(); } return encDecKey; }
/// <summary> /// Call this within a transaction. /// </summary> /// <param name="originalSubject"></param> /// <param name="singleFco"></param> /// <param name="OutputSubDir"></param> public void UpdateResultsJson( MgaFCO singleFco, string OutputSubDir) { string jsonFile = Path.Combine(Path.GetDirectoryName(this.m_filename), "results", "results.metaresults.json"); AVM.DDP.MetaResults results = null; bool createdNew; using (System.Threading.Mutex jsonFileMutex = new System.Threading.Mutex(false, "results_metaresults_mutex", out createdNew)) { jsonFileMutex.WaitOne(); try { if (File.Exists(jsonFile)) { string content = ""; using (StreamReader reader = new StreamReader(jsonFile)) { content = reader.ReadToEnd(); } results = JsonConvert.DeserializeObject <AVM.DDP.MetaResults>(content); // TODO: remove broken links } else { results = new AVM.DDP.MetaResults(); } AVM.DDP.MetaResults.Result thisResult = new AVM.DDP.MetaResults.Result(); thisResult.Summary = MakeRelativePath( Path.GetDirectoryName(jsonFile), Path.Combine(OutputSubDir, AVM.DDP.MetaTBManifest.TESTBENCH_FILENAME)).Replace('\\', '/'); thisResult.Time = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"); thisResult.TestBench = singleFco.RegistryValue["TestBenchUniqueName"] + ".testbench.json"; if (singleFco.Meta.Name == typeof(CyPhy.TestBench).Name || singleFco.Meta.Name == typeof(CyPhy.ParametricExploration).Name || singleFco.Meta.Name == typeof(CyPhy.TestBenchSuite).Name) { CyPhy.TestBench testBench = null; if (singleFco.Meta.Name == typeof(CyPhy.TestBench).Name) { testBench = ISIS.GME.Dsml.CyPhyML.Classes.TestBench.Cast(singleFco); } else if (singleFco.Meta.Name == typeof(CyPhy.ParametricExploration).Name) { var pet = ISIS.GME.Dsml.CyPhyML.Classes.ParametricExploration.Cast(singleFco); testBench = pet.Children.TestBenchRefCollection.FirstOrDefault().Referred.TestBench; } else if (singleFco.Meta.Name == typeof(CyPhy.TestBenchSuite).Name) { var pet = ISIS.GME.Dsml.CyPhyML.Classes.TestBenchSuite.Cast(singleFco); testBench = pet.Children.TestBenchRefCollection.FirstOrDefault().Referred.TestBench; } var tlsut = testBench.Children.TopLevelSystemUnderTestCollection.FirstOrDefault(); if (tlsut != null) { if (tlsut.Referred.ComponentAssembly != null) { var cfg = tlsut.Referred.ComponentAssembly; thisResult.Design = cfg.Name + ".metadesign.json"; var cid = cfg.Attributes.ConfigurationUniqueID; //this.ConfigurationUniqueID = cid; if (string.IsNullOrWhiteSpace(cid)) { cid = Guid.NewGuid().ToString("B"); cfg.Attributes.ConfigurationUniqueID = cid; } if (!string.IsNullOrEmpty(cid)) { try { Guid guid = new Guid(cid); thisResult.DesignID = guid.ToString("B"); } catch (System.FormatException ex) { Trace.TraceError("{0} is not a vaild GUID.", cid); Trace.TraceError(ex.ToString()); } } } } } results.Results.Add(thisResult); var dirname = Path.GetDirectoryName(jsonFile); if (Directory.Exists(dirname) == false) { Directory.CreateDirectory(dirname); } using (StreamWriter writer = new StreamWriter(jsonFile)) { writer.WriteLine(JsonConvert.SerializeObject(results, Newtonsoft.Json.Formatting.Indented)); } } finally { jsonFileMutex.ReleaseMutex(); jsonFileMutex.Dispose(); } } }
public void Dispose() { jsonFileMutex.ReleaseMutex(); jsonFileMutex.Dispose(); }
public void Dispose() { mutex.Dispose(); }
/// <summary> /// Call this within a transaction. /// </summary> /// <param name="originalSubject"></param> /// <param name="singleFco"></param> /// <param name="OutputSubDir"></param> public void UpdateResultsJson( MgaFCO singleFco, string OutputSubDir) { string jsonFile = Path.Combine(Path.GetDirectoryName(this.m_filename), "results", "results.metaresults.json"); AVM.DDP.MetaResults results = null; bool createdNew; using (System.Threading.Mutex jsonFileMutex = new System.Threading.Mutex(false, "results_metaresults_mutex", out createdNew)) { jsonFileMutex.WaitOne(); try { if (File.Exists(jsonFile)) { string content = ""; using (StreamReader reader = new StreamReader(jsonFile)) { content = reader.ReadToEnd(); } results = JsonConvert.DeserializeObject<AVM.DDP.MetaResults>(content); // TODO: remove broken links } else { results = new AVM.DDP.MetaResults(); } AVM.DDP.MetaResults.Result thisResult = new AVM.DDP.MetaResults.Result(); thisResult.Summary = MakeRelativePath( Path.GetDirectoryName(jsonFile), Path.Combine(OutputSubDir, AVM.DDP.MetaTBManifest.TESTBENCH_FILENAME)).Replace('\\', '/'); thisResult.Time = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"); thisResult.TestBench = singleFco.RegistryValue["TestBenchUniqueName"] + ".testbench.json"; if (singleFco.Meta.Name == typeof(CyPhy.TestBench).Name || singleFco.Meta.Name == typeof(CyPhy.ParametricExploration).Name || singleFco.Meta.Name == typeof(CyPhy.TestBenchSuite).Name) { CyPhy.TestBench testBench = null; if (singleFco.Meta.Name == typeof(CyPhy.TestBench).Name) { testBench = ISIS.GME.Dsml.CyPhyML.Classes.TestBench.Cast(singleFco); } else if (singleFco.Meta.Name == typeof(CyPhy.ParametricExploration).Name) { var pet = ISIS.GME.Dsml.CyPhyML.Classes.ParametricExploration.Cast(singleFco); testBench = pet.Children.TestBenchRefCollection.FirstOrDefault().Referred.TestBench; } else if (singleFco.Meta.Name == typeof(CyPhy.TestBenchSuite).Name) { var pet = ISIS.GME.Dsml.CyPhyML.Classes.TestBenchSuite.Cast(singleFco); testBench = pet.Children.TestBenchRefCollection.FirstOrDefault().Referred.TestBench; } var tlsut = testBench.Children.TopLevelSystemUnderTestCollection.FirstOrDefault(); if (tlsut != null) { if (tlsut.Referred.ComponentAssembly != null) { var cfg = tlsut.Referred.ComponentAssembly; thisResult.Design = cfg.Name + ".metadesign.json"; var cid = cfg.Attributes.ConfigurationUniqueID; //this.ConfigurationUniqueID = cid; if (string.IsNullOrWhiteSpace(cid)) { cid = Guid.NewGuid().ToString("B"); cfg.Attributes.ConfigurationUniqueID = cid; } if (!string.IsNullOrEmpty(cid)) { try { Guid guid = new Guid(cid); thisResult.DesignID = guid.ToString("B"); } catch (System.FormatException ex) { Trace.TraceError("{0} is not a vaild GUID.", cid); Trace.TraceError(ex.ToString()); } } } } } results.Results.Add(thisResult); var dirname = Path.GetDirectoryName(jsonFile); if (Directory.Exists(dirname) == false) { Directory.CreateDirectory(dirname); } using (StreamWriter writer = new StreamWriter(jsonFile)) { writer.WriteLine(JsonConvert.SerializeObject(results, Newtonsoft.Json.Formatting.Indented)); } } finally { jsonFileMutex.ReleaseMutex(); jsonFileMutex.Dispose(); } } }