本文整理汇总了C#中System.Threading.ManualResetEvent.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ManualResetEvent.Close方法的具体用法?C# ManualResetEvent.Close怎么用?C# ManualResetEvent.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.ManualResetEvent
的用法示例。
在下文中一共展示了ManualResetEvent.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
_osCommands.CheckToSeeIfServiceRunning(_description);
try
{
_log.Debug("Starting up as Azure worker role");
_exit = new ManualResetEvent(false);
_coordinator.Start(); //user code starts
_log.InfoFormat("[Topshelf] Running.");
_exit.WaitOne();
}
catch (Exception ex)
{
_log.Error("An exception occurred", ex);
}
finally
{
ShutdownCoordinator();
_exit.Close();
}
}
示例2: Run
public void Run()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
CheckToSeeIfWinServiceRunning();
try
{
_log.Debug("Starting up as a console application");
_exit = new ManualResetEvent(false);
Console.CancelKeyPress += HandleCancelKeyPress;
_coordinator.Start(); //user code starts
_log.InfoFormat("[Topshelf] Running, press Control+C to exit.");
_exit.WaitOne();
}
catch (Exception ex)
{
_log.Error("An exception occurred", ex);
}
finally
{
ShutdownCoordinator();
}
_exit.Close();
_exit = null;
}
示例3: Wait
public void Wait()
{
SpinWait s = new SpinWait();
while (m_state == 0)
{
if (s.Spin() >= s_spinCount)
{
if (m_eventObj == null)
{
ManualResetEvent newEvent =
new ManualResetEvent(m_state == 1);
if (Interlocked.CompareExchange<EventWaitHandle>(
ref m_eventObj, newEvent, null) == null)
{
// If someone set the flag before seeing the new
// event obj, we must ensure it’s been set.
if (m_state == 1)
m_eventObj.Set();
}
else
{
// Lost the race w/ another thread. Just use
// its event.
newEvent.Close();
}
}
m_eventObj.WaitOne();
}
}
}
示例4: OnStart
/// <summary>
/// Called when the service is started.
/// </summary>
protected void OnStart(string[] args)
{
try
{
Thread serviceThread = new Thread(new ParameterizedThreadStart(StartAsync));
ManualResetEvent serviceStarting = new ManualResetEvent(false);
serviceThread.Start(serviceStarting);
serviceStarting.WaitOne();
serviceStarting.Close();
foreach (ScheduleBase schedule in ScheduleManager.GetSchedules())
{
schedule.Settings.LastElapsed = new DateTime(0);
ObjectHelper wrapper = new ObjectHelper(schedule);
if (wrapper.HasProperty("TimeOfDay"))
{
wrapper.SetValue("TimeOfDay", DateTime.Now.TimeOfDay);
}
if (wrapper.HasProperty("DayOfMonth"))
{
wrapper.SetValue("DayOfMonth", DayOfMonth.AllDays);
}
}
}
catch (ThreadAbortException)
{
// do nothing.
}
}
示例5: MarkForDeletion
/// <summary>
/// Marks message as deleted.
/// </summary>
/// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
/// <exception cref="POP3_ClientException">Is raised when POP3 serveer returns error.</exception>
public void MarkForDeletion()
{
if(this.IsDisposed){
throw new ObjectDisposedException(this.GetType().Name);
}
if(this.IsMarkedForDeletion){
return;
}
using(MarkForDeletionAsyncOP op = new MarkForDeletionAsyncOP()){
using(ManualResetEvent wait = new ManualResetEvent(false)){
op.CompletedAsync += delegate(object s1,EventArgs<MarkForDeletionAsyncOP> e1){
wait.Set();
};
if(!this.MarkForDeletionAsync(op)){
wait.Set();
}
wait.WaitOne();
wait.Close();
if(op.Error != null){
throw op.Error;
}
}
}
}
示例6: GetConfig_CanLoadConfigsFromMultipleThreads
public void GetConfig_CanLoadConfigsFromMultipleThreads() {
const string configKey = "MyCustomConfig";
var configLoader = new FakeLoader(false, true);
var configRepository = new ConfigRepository(configLoader);
const int maxThreads = 10;
Exception ex = null;
IConfig config = null;
var getConfigCompletedEvent = new ManualResetEvent(false);
for(int i = 0; i < maxThreads; i++) {
int remainingThreads = i;
ThreadPool.QueueUserWorkItem(s => {
try {
config = configRepository.GetConfig(configKey, false);
if(Interlocked.Decrement(ref remainingThreads) == 0) {
getConfigCompletedEvent.Set();
}
} catch(Exception innerEx) {
getConfigCompletedEvent.Set();
ex = innerEx;
throw;
}
});
}
getConfigCompletedEvent.WaitOne();
getConfigCompletedEvent.Close();
Assert.IsNotNull(config);
Assert.IsNull(ex);
}
示例7: EventLoggerLogErrorException
public void EventLoggerLogErrorException()
{
ManualResetEvent handle = new ManualResetEvent(false);
try
{
EventLogger logger = new EventLogger();
Exception ex = new Exception();
logger.Log += (sender, args) =>
{
Assert.AreEqual(EventLoggerEventType.Error, args.EventType);
Assert.AreEqual(string.Empty, args.Message);
Assert.AreEqual(ex, args.Exception);
handle.Set();
};
logger.Error(ex);
WaitHandle.WaitAll(new WaitHandle[] { handle });
}
finally
{
handle.Close();
}
}
示例8: Dispose
public void Dispose()
{
WaitHandle notifyObject = new ManualResetEvent(false);
_superLayerHideTimer.Dispose(notifyObject);
notifyObject.WaitOne();
notifyObject.Close();
}
示例9: Wait
/// <summary>
/// Wait Event State to Set
/// </summary>
public void Wait() {
if(IsDebugEnabled)
log.Debug("Wait event state to SET...");
var spinWait = new System.Threading.SpinWait();
var spinCount = 0;
while(_state == UN_SET) {
if(spinCount++ < SpinCount) {
spinWait.SpinOnce();
if(_eventObj == null) {
var mre = new ManualResetEvent(_state == SET);
if(Interlocked.CompareExchange(ref _eventObj, mre, null) != null) {
// If someone set the flag before seeing the new event object, we must ensure it's been set.
if(_state == SET)
_eventObj.Set();
// Lost the race w/ another thread. Just use its event.
else
mre.Close();
}
if(_eventObj != null)
_eventObj.WaitOne();
}
}
}
}
示例10: BootstrapsBasicApplicationFileChange
public void BootstrapsBasicApplicationFileChange()
{
string path = ApplicationUtils.CreateValidExampleApplication();
string filePath = Path.Combine(path, Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".dll");
ManualResetEvent handle = new ManualResetEvent(false);
try
{
using (Bootstraps bootstraps = new Bootstraps(path, null, 500))
{
bootstraps.ApplicationFilesChanged += (sender, e) =>
{
Assert.AreEqual(filePath, e.FullPath);
handle.Set();
};
Assert.AreEqual(BootstrapsPullupResultType.Success, bootstraps.PullUp().ResultType);
using (File.Create(filePath))
{
}
WaitHandle.WaitAll(new WaitHandle[] { handle });
}
}
finally
{
handle.Close();
}
}
示例11: WorkerProcessMain
public void WorkerProcessMain(string argument, string passwordBase64)
{
int port = int.Parse(argument, CultureInfo.InvariantCulture);
client = new TcpClient();
client.Connect(new IPEndPoint(IPAddress.Loopback, port));
Stream stream = client.GetStream();
receiver = new PacketReceiver();
sender = new PacketSender(stream);
shutdownEvent = new ManualResetEvent(false);
receiver.ConnectionLost += OnConnectionLost;
receiver.PacketReceived += OnPacketReceived;
sender.WriteFailed += OnConnectionLost;
// send password
sender.Send(Convert.FromBase64String(passwordBase64));
receiver.StartReceive(stream);
while (!shutdownEvent.WaitOne(SendKeepAliveInterval, false)) {
Program.Log("Sending keep-alive packet");
sender.Send(new byte[0]);
}
Program.Log("Closing client (end of WorkerProcessMain)");
client.Close();
shutdownEvent.Close();
}
示例12: UsbIOSync
internal static bool UsbIOSync(SafeHandle dev, int code, Object inBuffer, int inSize, IntPtr outBuffer, int outSize, out int ret)
{
SafeOverlapped deviceIoOverlapped = new SafeOverlapped();
ManualResetEvent hEvent = new ManualResetEvent(false);
deviceIoOverlapped.ClearAndSetEvent(hEvent.SafeWaitHandle.DangerousGetHandle());
ret = 0;
if (!Kernel32.DeviceIoControlAsObject(dev, code, inBuffer, inSize, outBuffer, outSize, ref ret, deviceIoOverlapped.GlobalOverlapped))
{
int iError = Marshal.GetLastWin32Error();
if (iError != ERROR_IO_PENDING)
{
// Don't log errors for these control codes.
do
{
if (code == LibUsbIoCtl.GET_REG_PROPERTY) break;
if (code == LibUsbIoCtl.GET_CUSTOM_REG_PROPERTY) break;
UsbError.Error(ErrorCode.Win32Error, iError, String.Format("DeviceIoControl code {0:X8} failed:{1}", code, Kernel32.FormatSystemMessage(iError)), typeof(LibUsbDriverIO));
} while (false);
hEvent.Close();
return false;
}
}
if (Kernel32.GetOverlappedResult(dev, deviceIoOverlapped.GlobalOverlapped, out ret, true))
{
hEvent.Close();
return true;
}
UsbError.Error(ErrorCode.Win32Error, Marshal.GetLastWin32Error(), "GetOverlappedResult failed.\nIoCtlCode:" + code, typeof(LibUsbDriverIO));
hEvent.Close();
return false;
}
示例13: AcceptAsyncShouldUseAcceptSocketFromEventArgs
public void AcceptAsyncShouldUseAcceptSocketFromEventArgs()
{
var readyEvent = new ManualResetEvent(false);
var mainEvent = new ManualResetEvent(false);
var listenSocket = new Socket(
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var serverSocket = new Socket(
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Socket acceptedSocket = null;
Exception ex = null;
ThreadPool.QueueUserWorkItem(_ =>
{
SocketAsyncEventArgs asyncEventArgs;
try {
listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
listenSocket.Listen(1);
asyncEventArgs = new SocketAsyncEventArgs {AcceptSocket = serverSocket};
asyncEventArgs.Completed += (s, e) =>
{
acceptedSocket = e.AcceptSocket;
mainEvent.Set();
};
} catch (Exception e) {
ex = e;
return;
} finally {
readyEvent.Set();
}
try {
if (listenSocket.AcceptAsync(asyncEventArgs))
return;
acceptedSocket = asyncEventArgs.AcceptSocket;
mainEvent.Set();
} catch (Exception e) {
ex = e;
}
});
Assert.IsTrue(readyEvent.WaitOne(1500));
if (ex != null)
throw ex;
var clientSocket = new Socket(
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
clientSocket.Connect(listenSocket.LocalEndPoint);
clientSocket.NoDelay = true;
Assert.IsTrue(mainEvent.WaitOne(1500));
Assert.AreEqual(serverSocket, acceptedSocket, "x");
mainEvent.Reset();
if (acceptedSocket != null)
acceptedSocket.Close();
listenSocket.Close();
readyEvent.Close();
mainEvent.Close();
}
示例14: GetManualResetEvent
/// <summary>
/// Create a <see cref="ManualResetEvent"/> wrapper around the given native event.
/// </summary>
/// <param name="handle">The handle of the native event.</param>
/// <returns>A <see cref="ManualResetEvent"/> wrapping the given <paramref name="handle"/>.</returns>
public static ManualResetEvent GetManualResetEvent( IntPtr handle )
{
ManualResetEvent ev = new ManualResetEvent( false );
ev.Close();
GC.ReRegisterForFinalize( ev );
ev.SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle( handle, false );
return ev;
}
示例15: OnStart
protected override void OnStart(string[] args)
{
base.OnStart(args);
Thread serviceThread = new Thread(new ParameterizedThreadStart(RunProcess));
ManualResetEvent serviceStarting = new ManualResetEvent(false);
serviceThread.Start(serviceStarting);
serviceStarting.WaitOne();
serviceStarting.Close();
}