当前位置: 首页>>代码示例>>C#>>正文


C# System.Threading.Mutex.Dispose方法代码示例

本文整理汇总了C#中System.Threading.Mutex.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Mutex.Dispose方法的具体用法?C# System.Threading.Mutex.Dispose怎么用?C# System.Threading.Mutex.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Mutex的用法示例。


在下文中一共展示了System.Threading.Mutex.Dispose方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        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);
            }
        }
开发者ID:ifidakov,项目名称:trunk,代码行数:27,代码来源:Program.cs

示例2: Button_Click

        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)));
        }
开发者ID:sklemmer,项目名称:plugin_sdk,代码行数:40,代码来源:MainWindow.xaml.cs

示例3: stop_instance

        /// <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;
        }
开发者ID:sklemmer,项目名称:plugin_sdk,代码行数:25,代码来源:PluginExportSHM.cs

示例4: UpdateResultsJson


//.........这里部分代码省略.........
            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();
                }
            }
        }
开发者ID:metamorph-inc,项目名称:meta-core,代码行数:101,代码来源:MetaAvmProject.cs

示例5: GenerateDashboardScriptFiles

        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();
            }
        }
开发者ID:metamorph-inc,项目名称:meta-core,代码行数:86,代码来源:CyPhyMasterInterpreterAPI.cs

示例6: EncodeDecodeKey

 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;
 }
开发者ID:chughes-3,项目名称:UpdateProductKey,代码行数:34,代码来源:WorkBookClass.cs


注:本文中的System.Threading.Mutex.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。