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


C# EventWaitHandle.Dispose方法代码示例

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


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

示例1: Disposed_Set

		public void Disposed_Set ()
		{
			var ewh = new EventWaitHandle (false, EventResetMode.ManualReset);
			ewh.Dispose();
			try {
				ewh.Set();
				Assert.Fail ();
			} catch (ObjectDisposedException) {
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:10,代码来源:EventWaitHandleTest.cs

示例2: OpenChannel

        /// <summary>
        /// Opens the server channel, including aborting any existing channels
        /// and retrying.
        /// </summary>
        internal static bool OpenChannel(int retries, out IChannel channel, out EventWaitHandle notifyEvent)
        {
            // If anyone else is listening, abort them so they close the channel
            using (var evt = GetNotifyEvent()) {
                if (evt != null) {
                    evt.Set();
                }
            }

            channel = null;
            notifyEvent = null;

            while (retries-- > 0) {
                try {
                    // We have to open an IPC channel with a single global name,
                    // since our test adapter has no way to know which VS
                    // instance started it. We will only keep the channel open
                    // for a short period, and close it immediately when we stop
                    // debugging. As long as you don't attempt to debug two unit
                    // tests in two different VS instances at the same time,
                    // nobody should get confused.
                    notifyEvent = CreateNotifyEvent();
                    channel = Internal.VSTestHostPackage.RegisterChannel(DebugConnectionChannelName);
                    return true;
                } catch (RemotingException) {
                    // Someone else is already listening, so we need to abort
                    // them and try again.
                    using (var evt = GetNotifyEvent()) {
                        if (evt != null) {
                            evt.Set();
                        }
                    }
                }
            }

            if (channel != null) {
                ChannelServices.UnregisterChannel(channel);
                channel = null;
            }
            if (notifyEvent != null) {
                notifyEvent.Dispose();
                notifyEvent = null;
            }
            return false;
        }
开发者ID:ziyezizy7,项目名称:VisualStudio-TestHost,代码行数:49,代码来源:TesterDebugAttacher.cs

示例3: read_events_thread

        private void read_events_thread() {

            string prefix = use_global_ ? "Global\\" : "";
            try {
                memory_file_ = MemoryMappedFile.CreateNew(prefix + "DBWIN_BUFFER", 4096L);

                bool created = false;
                buffer_ready_ = new EventWaitHandle( false, EventResetMode.AutoReset, prefix + "DBWIN_BUFFER_READY", out created);
                if (!created) 
                    errors_.add("Can't create the DBWIN_BUFFER_READY event/" + use_global_);

                if (created) {
                    data_ready_ = new EventWaitHandle(false, EventResetMode.AutoReset, prefix + "DBWIN_DATA_READY", out created);
                    if (!created) 
                        errors_.add("Can't create the DBWIN_DATA_READY event/" + use_global_);
                }

                if (created) {
                    buffer_ready_.Set();
                    while (!disposed_) {
                        if (!data_ready_.WaitOne(1000))
                            continue;

                        using (var stream = memory_file_.CreateViewStream()) {
                            using (var reader = new BinaryReader(stream, Encoding.Default)) {
                                var process_id = (int)reader.ReadUInt32();
                                var raw = reader.ReadChars(4092);
                                var idx = Array.IndexOf(raw, '\0');
                                var msg = new string(raw, 0, idx);
                                find_process_id(process_id);
                                string process_name = pid_to_name_.ContainsKey(process_id) ? pid_to_name_[process_id] : "";
                                lock (this)
                                    events_.Add(new debug_event {
                                        unique_id = next_unique_id++, process_id = process_id, msg = msg, lo_process_name = process_name
                                    });
                            }
                        }
                
                        buffer_ready_.Set();
                    }
                }
            } catch (Exception e) {
                logger.Fatal("Can't read debug events " + e.Message);
                errors_.add("Error reading debug events " + e.Message);
            }

            if ( memory_file_ != null)
                memory_file_.Dispose();
            if ( data_ready_ != null)
                data_ready_.Dispose();
            if ( buffer_ready_ != null)
                buffer_ready_.Dispose();

        }
开发者ID:CaulyKan,项目名称:logwizard,代码行数:54,代码来源:capture_all_debug_events.cs

示例4: DoubleLaunchLocker

		public DoubleLaunchLocker(string signalId, string waitId, bool force = false, Action shuttingDown = null)
		{
			SignalId = signalId;
			WaitId = waitId;
			_force = force;
			ShuttingDown = shuttingDown;

			bool isNew;
			_signalHandler = new EventWaitHandle(false, EventResetMode.AutoReset, signalId, out isNew);
			if (!isNew)
			{
				Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
				bool terminate = false;
				if (!force && !RequestConfirmation())
					terminate = true;
				if (!terminate)
				{
					_waitHandler = new EventWaitHandle(false, EventResetMode.AutoReset, waitId);
					_signalHandler.Dispose();
					_signalHandler = new EventWaitHandle(false, EventResetMode.ManualReset, signalId, out isNew);
					if (!isNew)
					{
						_signalHandler.Set();
						terminate = !_waitHandler.WaitOne(TIMEOUT);
					}
				}
				if (terminate)
				{
					TryShutdown();
					ForceShutdown();
				}
				else
					Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose;
			}
			ThreadPool.QueueUserWorkItem(WaitingHandler, waitId);
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:36,代码来源:SingleLaunchHelper.cs

示例5: Start


//.........这里部分代码省略.........
                            }

                            while (!_cancellationTokenSource.IsCancellationRequested) {
                                sessionAckEvent.Set();
                                globalAckEvent.Set();

                                try {
                                    var i = WaitHandle.WaitAny(new[] {
                                        sessionReadyEvent, globalReadyEvent, _cancellationTokenSource.Token.WaitHandle
                                    });
                                    var now = DateTime.Now;
                                    if (i == 0) {
                                        lock (queue) {
                                            queue.Enqueue(new Tuple<int, DateTime, string>(Marshal.ReadInt32(sessionSharedMemoryHandle), now, Marshal.PtrToStringAnsi(sessionStringPointer)));
                                            dataAvailable.Set();
                                        }
                                    }

                                    if (i == 1) {
                                        lock (queue) {
                                            queue.Enqueue(new Tuple<int, DateTime, string>(Marshal.ReadInt32(globalSharedMemoryHandle), now, Marshal.PtrToStringAnsi(globalStringPointer)));
                                            dataAvailable.Set();
                                        }
                                    }
                                } catch {
                                    // it's over. 
                                    _cancellationTokenSource.Cancel();
                                }
                            }
                            _listenTask = null;

                            // cleanup after stopping.
                            globalAckEvent.Reset();
                            globalAckEvent.Dispose();
                            globalAckEvent = null;

                            sessionAckEvent.Reset();
                            sessionAckEvent.Dispose();
                            sessionAckEvent = null;

                            globalReadyEvent.Reset();
                            globalReadyEvent.Dispose();
                            globalReadyEvent = null;

                            sessionReadyEvent.Reset();
                            sessionReadyEvent.Dispose();
                            sessionReadyEvent = null;

                            // Close SharedFile
                            if (sessionSharedFileHandle != IntPtr.Zero) {
                                if (!Kernel32.CloseHandle(sessionSharedFileHandle)) {
                                    throw new ApplicationException(
                                        string.Format("{0}. Last Win32 Error was {1}", "Failed to close handle for 'SharedFile'", Marshal.GetLastWin32Error()));
                                }
                                sessionSharedFileHandle = IntPtr.Zero;
                            }

                            // Unmap SharedMem
                            if (sessionSharedMemoryHandle != IntPtr.Zero) {
                                if (!Kernel32.UnmapViewOfFile(sessionSharedMemoryHandle)) {
                                    throw new ApplicationException(
                                        string.Format(
                                            "{0}. Last Win32 Error was {1}", "Failed to unmap view for slot 'DBWIN_BUFFER'", Marshal.GetLastWin32Error()));
                                }
                                sessionSharedMemoryHandle = IntPtr.Zero;
                            }
开发者ID:roomaroo,项目名称:coapp.powershell,代码行数:67,代码来源:Monitor.cs

示例6: ResolveToString

        public override string ResolveToString()
        {
            if (!Parameters.Contains("url") || string.IsNullOrEmpty(Parameters["url"].ToString()))
                throw new InvalidOperationException();

            string url = Parameters["url"].ToString();

            string resultString = null;

            using (var wc = new WebClient())
            {
                var tlock = new EventWaitHandle(false, EventResetMode.ManualReset);
                wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler((sender, e) =>
                {
                    // TODO: Add progress monitoring
                });
                wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler((sender, e) =>
                {
                    resultString = e.Result;
                    tlock.Set();
                });
                wc.DownloadStringAsync(new Uri(url));
                tlock.WaitOne();
                tlock.Dispose();
            }

            return resultString;
        }
开发者ID:Craftitude-Team,项目名称:Craftitude-ClientApi,代码行数:28,代码来源:DownloadResolver.cs

示例7: RunTest

        private void RunTest()
        {
            Logger logger = eventLogControl.Logger;
            MetaDictionary globals = new MetaDictionary();
            EventWaitHandle endEvent = new EventWaitHandle(false, EventResetMode.ManualReset);

            try
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource();
                using (TestDocument.TestGraphContainer testGraph = Document.CreateTestGraph(logger, globals))
                {
                    testGraph.Graph.LogPacketEvent += new EventHandler<LogPacketEventArgs>(log_AddLogPacket);
                    testGraph.Graph.EditPacketEvent += new EventHandler<EditPacketEventArgs>(Graph_EditPacketEvent);

                    LogPacket[] packets = Document.GetInputPackets();

                    using (QueuedDataAdapter inputAdapter = new QueuedDataAdapter(tokenSource.Token))
                    {
                        foreach (LogPacket p in packets)
                        {
                            inputAdapter.Enqueue(p.Frame.CloneFrame());
                        }

                        inputAdapter.StopEnqueue();

                        testGraph.Graph.BindEndpoint(testGraph.Output.Uuid, new EventDataAdapter(endEvent));
                        testGraph.Graph.BindEndpoint(testGraph.Input.Uuid, inputAdapter);

                        IPipelineEndpoint inputEndpoint = testGraph.Input as IPipelineEndpoint;
                        inputEndpoint.Start();

                        // Sleep up to 100 seconds
                        if (!endEvent.WaitOne(100000))
                        {
                            logger.LogError("Test did not finish after 100 seconds");
                            tokenSource.Cancel();
                        }
                    }
                }
            }
            catch (EndOfStreamException)
            {
                // End of stream
            }
            catch (ThreadAbortException)
            {
            }
            catch (ObjectDisposedException)
            {
            }
            finally
            {
                if(endEvent != null)
                {
                    endEvent.Dispose();
                }
            }
        }
开发者ID:michyer,项目名称:canape,代码行数:58,代码来源:GraphTestControl.cs


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