static void Connection_Error(object sender, ZyanErrorEventArgs e) { if (e.Exception is SocketException || e.Exception is InvalidSessionException || e.Exception is RemotingException) { int retryCount = 0; bool problemSolved = false; while (!problemSolved && retryCount < 10) { Thread.Sleep(5000); problemSolved = Connection.Reconnect(); retryCount++; } if (problemSolved) { e.Action = ZyanErrorAction.Retry; } else { e.Action = ZyanErrorAction.ThrowException; } } else { e.Action = ZyanErrorAction.ThrowException; } }
static void ConnectionErrorHandler(object sender, ZyanErrorEventArgs args) { var exception = args.Exception.InnerException ?? args.Exception; Console.WriteLine("Exception caught: {0}", exception.Message); Console.WriteLine("Retry (default)? Ignore? Throw exception?"); var c = char.ToUpperInvariant(Console.ReadKey(true).KeyChar); switch (c) { case 'I': args.Action = ZyanErrorAction.Ignore; break; case 'T': args.Action = ZyanErrorAction.ThrowException; break; default: args.Action = ZyanErrorAction.Retry; break; } }