public void Dispose() { if (m_bIsDisposed == false) { GotEvent.Close(); GotEvent.Dispose(); m_bIsDisposed = true; } }
/// <summary> /// Splashフォームを消す /// </summary> public static void CloseSplash() { lock (syncObject) { if (_thread == null) { return; } if (_mainForm != null) { _mainForm.Activated -= new EventHandler(_mainForm_Activated); } //Splashが表示されるまで待機する if (splashShownEvent != null) { splashShownEvent.WaitOne(); splashShownEvent.Close(); splashShownEvent = null; } //Splashフォームを閉じる //Invokeが必要か調べる if (_form != null) { if (_form.InvokeRequired) { _form.Invoke(new MethodInvoker(CloseLogoWindow)); } else { CloseLogoWindow(); } } //メインフォームをアクティブにする if (_mainForm != null) { if (_mainForm.InvokeRequired) { _mainForm.Invoke(new MethodInvoker(ActivateMainForm)); } else { ActivateMainForm(); } } _form = null; _thread = null; _mainForm = null; } }
public void Dispose() { lock (this) { if (_SSendEvent != null) { _SSendEvent.Close(); _SSendEvent = null; } } }
/// <summary> /// 释放资源 /// </summary> private void Dispose() { if (_event != null) { _event.Close(); } _event = null; _proc = null; _procHandle = null; _timeoutHandle = null; }
public void Dispose() { if (doEvent != null) { doEvent.Close(); } doEvent = null; willDoProc = null; timeOutDoProc = null; userDefineProc = null; }
public void Wait() { if (IsCompleted) { return; } lock (job) { if (IsCompleted) { return; } complete = new System.Threading.ManualResetEvent(false); } complete.WaitOne(); complete.Close(); complete = null; }
private void TestNotifyEndOfStream() { int hr; IPin iPin = m_pc as IPin; System.Threading.ManualResetEvent mre = new System.Threading.ManualResetEvent(false); hr = m_pc.NotifyEndOfStream(mre.SafeWaitHandle.DangerousGetHandle()); DsError.ThrowExceptionForHR(hr); hr = iPin.EndOfStream(); DsError.ThrowExceptionForHR(hr); mre.WaitOne(); mre.Close(); // If NotifyEndOfStream wasn't working, we'd never get here. hr = m_pc.NotifyEndOfStream(IntPtr.Zero); DsError.ThrowExceptionForHR(hr); }
public static void RunInUnityThreadAndWait(Action act) { if (act != null) { if (ThreadLocalObj.GetThreadId() == ThreadSafeValues.UnityThreadID) { act(); } else { System.Threading.ManualResetEvent waithandle = new System.Threading.ManualResetEvent(false); AddEvent(() => { act(); waithandle.Set(); }); waithandle.WaitOne(); waithandle.Close(); } } }
public virtual void Dispose() { if (!disposed) { disposing = true; Disconnect("Dispose"); allDone.Close(); buffer = null; localAddress = null; remoteAddress = null; ProtocolChange -= OnProtocolChanged; // ConnectionStatusChange need to be removed after calling Disconnect as Disconnect fires ConnectionStatusChange; ConnectionStatusChange -= OnConnectionStatusChanged; #if !COMPACT_FRAMEWORK SecureUpdate -= OnSecureUpdate; #endif if (socket != null) { socket.Close(); socket = null; } if (protocol != null) { protocol.Dispose(); protocol = null; } #if !COMPACT_FRAMEWORK if (secStream != null) { secStream.Dispose(); secStream = null; } #endif GC.SuppressFinalize(this); disposed = true; disposing = false; } }
private void ReleaseResources() { try { _CloseEvent.Close(); } catch { } try { _Event.Close(); } catch { } _CloseEvent = null; _Event = null; _Thread = null; Started = false; }
public bool Wait(TimeSpan timeout, out T value) { var isSafeToClose = false; try { if (timeout == TimeSpan.MaxValue) { waitEvent.WaitOne(); } else if (!waitEvent.WaitOne(timeout, false)) { if (inputQueue.RemoveReader(this)) { value = default(T); isSafeToClose = true; return(false); } else { waitEvent.WaitOne(); } } isSafeToClose = true; } finally { if (isSafeToClose) { waitEvent.Close(); } } value = item; return(true); }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">True if managed resources should be disposed; otherwise, false.</param> protected virtual void Dispose(bool disposing) { if (disposing) { lock (_syncRoot) { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; _hideEvent.Set(); _hideEvent.Close(); if (_form != null) { if (_form.IsHandleCreated) { CloseFormDelegate methodCloseForm = new CloseFormDelegate(CloseForm); _form.Invoke(methodCloseForm, _form); } if (!_form.IsDisposed) { _form.Dispose(); } _form = null; } if (_label != null) { _label.Dispose(); _label = null; } if (_progressBar != null) { _progressBar.Dispose(); _progressBar = null; } } } }
public static T RunInUnityThreadAndWait <T>(Func <T> func) { if (func != null) { if (ThreadLocalObj.GetThreadId() == ThreadSafeValues.UnityThreadID) { return(func()); } else { T rv = default(T); System.Threading.ManualResetEvent waithandle = new System.Threading.ManualResetEvent(false); AddEvent(() => { rv = func(); waithandle.Set(); }); waithandle.WaitOne(); waithandle.Close(); return(rv); } } return(default(T)); }
public void Dispose() { gate.Close(); }
/// <summary> /// The console application entry class /// </summary> /// <param name="args"> /// The command line arguments. /// </param> static void Main(string[] args) { try { // print the command line usage if the arguments do not match if (args.Length < 2) { Console.WriteLine("Usage: <server address | Game Mode> <port>"); Console.WriteLine("server address: ip or dns"); Console.WriteLine("Game Mode: texas,five,seven,omaha"); Console.WriteLine("port: the port in which the server runs"); } else { int port = -1; string serverIp = string.Empty; ServerGame game = ServerGame.FiveCardDraw; port = int.Parse(args[1]); // test to see if the game mode is recognized if (args[0] == "texas") { game = ServerGame.TexasHoldem; } else if (args[0] == "five") { game = ServerGame.FiveCardDraw; } else if (args[0] == "seven") { game = ServerGame.SevenCardStud; } else if (args[0] == "omaha") { game = ServerGame.OmahaHoldem; } else // assume the argument is an ip or dns { serverIp = args[0]; } // found a match to the game if (serverIp == string.Empty) { BaseEngine server = null; WcfEngineHost binaryHelper = new WcfEngineHost(); switch (game) { case ServerGame.FiveCardDraw: server = new FiveGameDrawServer(binaryHelper); break; case ServerGame.TexasHoldem: server = new TexasHoldemServer(binaryHelper); break; case ServerGame.SevenCardStud: server = new SevenCardStudServer(binaryHelper); break; case ServerGame.OmahaHoldem: server = new OmahaHoldemServer(binaryHelper); break; } System.Threading.ManualResetEvent waitHandle = new System.Threading.ManualResetEvent(false); binaryHelper.Initialize(server, game, port, waitHandle); // initialize the server and run until the game is over server.Initialize(); Console.WriteLine("Press enter to stop the registration"); Console.ReadLine(); waitHandle.Set(); server.Run(); waitHandle.Close(); } else { // if the arguments count is higher than 2 assume the process started will be played by an AI engine. bool useAi = args.Length > 2; // this is the base client which will hold the connected game ClientHelperBridge clientBridge = new ClientHelperBridge(); RulesInterpreterBridge rulesBridge = new RulesInterpreterBridge(); BaseWcfClient client = new BaseWcfClient(clientBridge); clientBridge.ClientHelper = new ConsoleClientHelper(rulesBridge); ServerDetails result = client.Initialize(serverIp, port); // check the result of the connection if (result.CanConnect) { IClientHelper outerClient = null; if (useAi) { switch (result.Game) { case ServerGame.FiveCardDraw: outerClient = new FiveGameDrawClient(new AiFiveCardDrawClient(new ConsoleFiveGameDrawClient(rulesBridge), rulesBridge)); break; case ServerGame.OmahaHoldem: outerClient = new OmahaHoldemClient(new AiClientHelper(new ConsoleTexasHoldemClient(rulesBridge, 4), rulesBridge)); break; case ServerGame.SevenCardStud: outerClient = new GameClient <SevenCardStudGame>(new AiClientHelper(new ConsoleClientHelper(rulesBridge), rulesBridge)); break; case ServerGame.TexasHoldem: outerClient = new GameClient <TexasHoldem>(new AiClientHelper(new ConsoleTexasHoldemClient(rulesBridge), rulesBridge)); break; } } else { switch (result.Game) { case ServerGame.FiveCardDraw: outerClient = new FiveGameDrawClient(new ConsoleFiveGameDrawClient(rulesBridge)); break; case ServerGame.OmahaHoldem: outerClient = new OmahaHoldemClient(new ConsoleTexasHoldemClient(rulesBridge, 4)); break; case ServerGame.SevenCardStud: outerClient = new GameClient <SevenCardStudGame>(new ConsoleClientHelper(rulesBridge)); break; case ServerGame.TexasHoldem: outerClient = new GameClient <TexasHoldem>(new ConsoleTexasHoldemClient(rulesBridge)); break; } } IRulesInterpreter interpreter = (IRulesInterpreter)outerClient; rulesBridge.Interpreter = interpreter; if (result.Game == ServerGame.FiveCardDraw) { clientBridge.FiveCardHelper = (IFiveCardClientHelper)outerClient; } else { clientBridge.ClientHelper = outerClient; } client.Connect(); // run until the game is over client.Run(); client.Disconnect(); } else { Console.WriteLine("Game is in progress. Server refused connection"); } } } } catch (Exception e) { // an error occured. print an unfriendly message Console.WriteLine("Uh oh, I did bad"); // when a debugger is attached, break it so you can learn of the error. if (System.Diagnostics.Debugger.IsAttached) { Console.WriteLine(e.Message); System.Diagnostics.Debugger.Break(); } } }