private static void ThreadStart() { TestClientService wcf = new TestClientService(); try { try { wcf.DoWork(); } catch (CommunicationException ex) { TraceLog(ex, wcf); wcf.Abort(); TraceProxy(wcf); throw new ApplicationException("CommunicationsException on proxy", ex); } catch (Exception ex) { TraceLog(ex, wcf); wcf.Abort(); TraceProxy(wcf); throw new ApplicationException("General Exception on proxy", ex); } finally { try { if (wcf.State != CommunicationState.Closed && wcf.State != CommunicationState.Faulted) { wcf.Close(); // may throw exception while closing TraceProxy(wcf); } else { wcf.Abort(); TraceProxy(wcf); } } catch (Exception cex) { TraceLog(cex, wcf); wcf.Abort(); TraceProxy(wcf); throw new ApplicationException("Failure closing proxy", cex); } } } catch (Exception) { // eat the exception } }
private static void TraceProxy(TestClientService proxy) { string msg = string.Format("Proxy #{0}, current channel state: {1} @ time: {2}", proxy.ProxyInstanceNum, proxy.State, DateTime.Now.ToString("HH:mm:ss.ffff")); Trace.WriteLine(msg); Console.WriteLine(msg); }
private static void TraceLog(Exception exType, TestClientService proxy) { string msg = string.Format("Proxy #{0}, with ExceptionType: {1}, ExceptionMessage: {2}", proxy.ProxyInstanceNum, exType.GetType().ToString(), exType.Message); Trace.WriteLine(msg); Console.WriteLine(msg); }