本文整理汇总了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) {
}
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
}