public static void SetSingleInstance(System.Windows.Application app, string windowName, out object idObj) { Mutex mutex; if (!IsNewInstance(windowName, out mutex)) { ActivateCurrentInstance(windowName); app.Startup += delegate { app.Shutdown(); }; } idObj = mutex; }
private static async void HandleExceptions(Task task, System.Windows.Application wpfApplication) { try { await Task.Yield(); //ensure this runs as a continuation await task; } catch (Exception ex) { //deal with exception, either with message box //or delegating to general exception handling logic you may have wired up //e.g. to Application.DispatcherUnhandledException and AppDomain.UnhandledException System.Windows.MessageBox.Show(ex.ToString()); wpfApplication.Shutdown(); } }
internal void QueuePoolForRelease(System.Data.ProviderBase.DbConnectionPool pool, bool clearing) { pool.Shutdown(); lock (this._poolsToRelease) { if (clearing) { pool.Clear(); } this._poolsToRelease.Add(pool); } this.PerformanceCounters.NumberOfInactiveConnectionPools.Increment(); }
void tc_Connected(TcpClient arg1, System.Net.Sockets.Socket sock) { try { if (!sock.Connected) return; Stream s = new NetworkStream(sock); StreamWriter sw = new StreamWriter(s); switch (act) { case requestType.setup: sw.WriteLine("SETUP {0} RTSP/1.0", abs_path); sw.WriteLine("Cseq: {0}", Csep++); sw.WriteLine("Transport: RTP/UDP; client_port= {0}", this.ur.getLocalPort()); break; case requestType.play: sw.WriteLine("PLAY {0} RTSP/1.0", abs_path); sw.WriteLine("Cseq: {0}", Csep++); sw.WriteLine("Session: {0}", session); break; case requestType.pause: sw.WriteLine("PAUSE {0} RTSP/1.0", abs_path); sw.WriteLine("Cseq: {0}", Csep++); sw.WriteLine("Session: {0}", session); break; case requestType.teardown: sw.WriteLine("TEARDOWN {0} RTSP/1.0", abs_path); sw.WriteLine("Cseq: {0}", Csep++); sw.WriteLine("Session: {0}", session); break; } sw.Flush(); sock.Shutdown(SocketShutdown.Send); StreamReader sr = new StreamReader(s); string respose = sr.ReadToEnd(); Regex session_rex = new Regex("^Session:\\s+(\\S+).*", RegexOptions.Multiline); session = session_rex.Match(respose).Groups[1].Value; responsed.Invoke(this, respose); } catch (Exception e) { Debug.WriteLine(e.StackTrace); } }