/// <summary>
        /// Returns the Python exception associated with a CLR exception
        /// creating a new Python exception if necessary.
        /// </summary>
        public static object ToPython(Exception clrException)
        {
            if (clrException.Data.Contains(pythonExceptionKey))
            {
                // this is already associated w/ a CLR exception.
                return(clrException.Data[pythonExceptionKey]);
            }

            ThreadAbortException ta = clrException as ThreadAbortException;

            if (ta != null)
            {
                // transform TA w/ our reason into a KeyboardInterrupt exception.
                PythonKeyboardInterrupt reason = ta.ExceptionState as PythonKeyboardInterrupt;
                if (reason != null)
                {
                    return(ToPython(reason));
                }
            }

            object res;
            ICustomExceptionConversion ice = clrException as ICustomExceptionConversion;

            if (ice != null)
            {
                res = ice.ToPythonException();
            }
            else
            {
                // this is an exception raised from CLR space crossing
                // into Python space.  We need to create a new Python
                // exception.
                DynamicType pythonType = GetPythonTypeFromCLR(clrException.GetType());

                // create new instance of Python type and save it (we do this directly
                // as we're calling during low-stack situations and don't want to invoke
                // a python method that would do a stack-check).
                res = new OldInstance((OldClass)pythonType);

                Ops.SetAttr(DefaultContext.Default, res, SymbolTable.ExceptionMessage, clrException.Message);
                if (clrException.Message != null)
                {
                    Ops.SetAttr(DefaultContext.Default, res, SymbolTable.Arguments, Tuple.MakeTuple(clrException.Message));
                }
                else
                {
                    Ops.SetAttr(DefaultContext.Default, res, SymbolTable.Arguments, Tuple.MakeTuple());
                }
                //'filename', 'lineno','offset', 'print_file_and_line', 'text'
            }

            OldInstance exRes = res as OldInstance;

            if (exRes != null)
            {
                AssociateExceptions(clrException, exRes);
            }

            return(res);
        }
Пример #2
0
        public void LogSwallowedException(Exception ex)
        {
            if (null == loggerInstance)
            {
                System.Diagnostics.Debug.Assert(false, "Attempt to LogSwallowedException to NamedTracer before initialization.");
                return;
            }

            ThreadAbortException threadAbortException = ex as ThreadAbortException;

            if (null != threadAbortException)
            {
                return;
            }

            LogEventInfo theEvent = new LogEventInfo
            {
                TimeStamp  = DateTime.Now,
                LoggerName = loggerInstance.Name,
                Level      = LogLevel.Trace,
                Message    = "SWALLOWED Exception: " + ex.ToDebugString(),
                Exception  = ex
            };

            theEvent.Properties["CorrelationId"] = ex.GetCorrelationId();
            SetSubprocessOriginator(theEvent);
            DebugMessageIntercept(theEvent);

            loggerInstance.Log(theEvent);
        }
Пример #3
0
    public void abortString () {
	try {
	    doThrow (10, "bla");
	} catch (ThreadAbortException e) {
	    exc = e;
	}
    }
Пример #4
0
 public void abortString()
 {
     try {
         doThrow(10, "bla");
     } catch (ThreadAbortException e) {
         exc = e;
     }
 }
Пример #5
0
 void IThreadPoolWorkItem.MarkAborted(ThreadAbortException exception)
 {
     if (!IsCompleted)
     {
         HandleException(exception);
         FinishThreadAbortedTask(true, false);
     }
 }
Пример #6
0
        public static string GetString(this ThreadAbortException exception)
        {
            if (exception.ExceptionState != null)
            {
                return(String.Format("{0}  {1}", exception.ExceptionState, exception));
            }

            return(exception.ToString());
        }
Пример #7
0
        internal static bool IsFatalException(Exception e) {
            ThreadAbortException tae = e as ThreadAbortException;
            if (tae != null) {
#if !FEATURE_EXCEPTION_STATE
                return true;
#else
                if ((tae.ExceptionState as KeyboardInterruptException) == null) {
                    return true;
                }
#endif
            }
            return false;
        }
Пример #8
0
        internal static bool IsFatalException(Exception e)
        {
            ThreadAbortException tae = e as ThreadAbortException;

            if (tae != null)
            {
                if ((tae.ExceptionState as KeyboardInterruptException) == null)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #9
0
        public static bool IsEqual(this ThreadAbortException @this, ThreadAbortException other)
        {
            // PolicyException is stubbed out in Core therefore we are skipping some equality checks.

            return(@this != null &&
                   other != null &&
                   // On full framework, line number may be method body start
                   // On Net Native we can't reflect on Exceptions and change its StackTrace
                   ((PlatformDetection.IsFullFramework || PlatformDetection.IsNetNative) ? true :
                    (@this.StackTrace == other.StackTrace)) &&
                   @this.Data.CheckSequenceEquals(other.Data) &&
                   @this.Source == other.Source &&
                   @this.HelpLink == other.HelpLink &&
                   CheckEquals(@this.InnerException, other.InnerException));
        }
Пример #10
0
        public static void PopExceptionHandler()
        {
            // _currentExceptions is thread static
            Debug.Assert(_currentExceptions != null);
            Debug.Assert(_currentExceptions.Count != 0);

#if !SILVERLIGHT
            ThreadAbortException tae = _currentExceptions[_currentExceptions.Count - 1] as ThreadAbortException;
            if (tae != null && tae.ExceptionState is KeyboardInterruptException)
            {
                Thread.ResetAbort();
            }
#endif
            _currentExceptions.RemoveAt(_currentExceptions.Count - 1);
        }
Пример #11
0
        public void AbortFromWithinProtectedScopeDoesNotOccurUntilTheProtectedScopeExits()
        {
            bool                 ranToCompletion = false;
            ThreadAbortScope     scope           = new ThreadAbortScope();
            ThreadAbortException ex = scope.Run(() =>
            {
                using (scope.Protect())
                {
                    scope.Abort();
                    ranToCompletion = true;
                }
            });

            Assert.IsNotNull(ex, "Should have aborted.");
            Assert.IsTrue(ranToCompletion, "Should have run the action.");
        }
        public void LogUnhandledException_EventArgsWithThreadAbortException_DoesLog()
        {
            // Arrange
            var moduleUnderTest = new TestAspNetExceptionLoggingModule();
            ThreadAbortException exceptionToLog = CreateThreadAbortException();

            var eventArgs = new UnhandledExceptionEventArgs(exceptionToLog, false);

            using (var scope = new LoggingProviderScope(ScopeOption.AllowOnlyASingleEntryToBeLogged))
            {
                // Act
                moduleUnderTest.LogUnhandledException(null, eventArgs);

                // Assert
                Assert.AreEqual(1, scope.LoggedEntries.Count());
            }
        }
Пример #13
0
        internal static bool IsFatalException(Exception e)
        {
            ThreadAbortException tae = e as ThreadAbortException;

            if (tae != null)
            {
#if SILVERLIGHT // ThreadAbortException.ExceptionState
                return(true);
#else
                if ((tae.ExceptionState as KeyboardInterruptException) == null)
                {
                    return(true);
                }
#endif
            }
            return(false);
        }
Пример #14
0
        public static void Finish(this ISpan span, Exception e)
        {
            var status = e switch
            {
                ThreadAbortException _ => SpanStatus.Aborted,
                TaskCanceledException _ => SpanStatus.Cancelled,
                OperationCanceledException _ => SpanStatus.Cancelled,
                NotImplementedException _ => SpanStatus.Unimplemented,
                ArgumentOutOfRangeException _ => SpanStatus.OutOfRange,
                IndexOutOfRangeException _ => SpanStatus.OutOfRange,
                _ => SpanStatus.InternalError
                // _ => SpanStatus.UnknownError
            };

            // TODO: Weak ref to Exception so that CaptureException later can find the span
            span.Finish(status);
        }
    }
Пример #15
0
        public void HandleThreadAbortException(ThreadAbortException mayBeHardTimeoutException)
        {
            if (mayBeHardTimeoutException == null)
            {
                throw new ArgumentNullException("mayBeHardTimeoutException");
            }

            Contract.EndContractBlock();

            if (RpcApplicationContext.HardTimeoutToken.Equals(mayBeHardTimeoutException.ExceptionState))
            {
                try
                {
                    ResetThreadAbort();
                }
                catch (SecurityException) { }
                catch (MemberAccessException) { }
            }
        }
 private void Cancel_Button_Click(object sender, EventArgs e)
 {
     if (this._waitThread.IsAlive)
     {
         try
         {
             this._waitThread.Abort();
         }
         catch (ThreadAbortException exception1)
         {
             ProjectData.SetProjectError(exception1);
             ThreadAbortException exception = exception1;
             Thread.ResetAbort();
             ProjectData.ClearProjectError();
         }
         finally
         {
             this._waitThread = null;
         }
     }
     this.DialogResult = DialogResult.Cancel;
     this.Close();
 }
 private void _Lambda$__92()
 {
     if (this._waitThread.IsAlive)
     {
         try
         {
             this._waitThread.Abort();
         }
         catch (ThreadAbortException exception1)
         {
             ProjectData.SetProjectError(exception1);
             ThreadAbortException exception = exception1;
             Thread.ResetAbort();
             ProjectData.ClearProjectError();
         }
         finally
         {
             this._waitThread = null;
         }
     }
     this.$VB$ClosureStub_set_DialogResult_MyBase(DialogResult.Cancel);
     this.$VB$ClosureStub_Close_MyBase();
 }
Пример #18
0
        private void Run()
        {
            try
            {
                try
                {
                    try
                    {
                        BeforeTask();

                        ThreadAbortException ex = threadAbortScope.Run(invoker.Invoke);

                        if (ex != null)
                        {
                            NotifyTerminated(TaskResult <object> .CreateFromException(ex));
                        }
                        else
                        {
                            NotifyTerminated(TaskResult <object> .CreateFromValue(invoker.Result));
                        }
                    }
                    finally
                    {
                        AfterTask();
                    }
                }
                catch (Exception ex)
                {
                    NotifyTerminated(TaskResult <object> .CreateFromException(ex));
                }
            }
            catch (Exception ex)
            {
                UnhandledExceptionPolicy.Report("An unhandled exception occurred in a thread task.", ex);
            }
        }
Пример #19
0
 public void MarkAborted(ThreadAbortException tae)
 {
 }
Пример #20
0
        private static void Handler(object sender, UnhandledExceptionEventArgs args)
        {
            // Wrap it all in a try catch, so as not to generate any extra errors at this point
            try
            {
                // The information to display or log
                string info;

                // Special case ThreadAbortExceptions during finalization
                ThreadAbortException tae = args.ExceptionObject as ThreadAbortException;
                if (tae != null)
                {
                    if (!args.IsTerminating)
                    {
                        return;
                    }
                }

                // Retrieve the exception object from the EventArgs
                Exception e = args.ExceptionObject as Exception;

                // Determine type of exception - CLS / Non-CLS
                if (e != null)
                {
                    // CLS-compliant - can access any Exception field (StackTrace, InnerException, etc.)
                    info = e.ToString();
                }
                else
                {
                    // Non-CLS compliant - can access methods defined by Object (ToString, GetType, etc.)
                    info = string.Format("Non-CLS compliant exception: ExceptionType:{0}, ExceptionString:{1}",
                                         args.ExceptionObject.GetType(), args.ExceptionObject.ToString());
                }

                // List type and string of Sender
                info += "\n\nSender type: " + sender.GetType();
                info += "\nSender string: " + sender.ToString();

                // Determine what type of thread caused the error
                info += "\nThread type: ";
                if (!args.IsTerminating)
                {
                    info += "pool or finalizer";
                }
                else
                {
                    info += "main or manual";
                }

                // Log version of product
                info += "\nProduct version: " + Application.ProductVersion.ToString();

                // Log it to the event log
                try
                {
                    EventLog eventLog = new EventLog("UnEx", ".", "MSR.LST.UnEx");
                    eventLog.WriteEntry(info, EventLogEntryType.Error, 999);
                }
                catch (Exception) {}

                // Compose message to user
                string msg = string.Format("{0} has encountered the following error:\n\n{1}",
                                           AppDomain.CurrentDomain.FriendlyName, info);

                // Read user's preference from configuration file
                bool showMsg = true;
                if (ConfigurationManager.AppSettings[AppConfig.LST_ShowErrors] != null)
                {
                    showMsg = bool.Parse(ConfigurationManager.AppSettings[AppConfig.LST_ShowErrors]);
                }

                if (showMsg)
                {
                    MessageBox.Show(msg);
                }
            }
            catch (Exception) {}
        }
Пример #21
0
        public static void RhpInitiateThreadAbort(IntPtr thread, bool rude)
        {
            Exception ex = new ThreadAbortException();

            RuntimeImports.RhpInitiateThreadAbort(thread, ex, rude);
        }
Пример #22
0
        }                                                     // 0x000000018075BD30-0x000000018075BD60

        void IThreadPoolWorkItem.MarkAborted(ThreadAbortException tae)
        {
        }                                                                         // 0x0000000180246DB0-0x0000000180246DC0
Пример #23
0
        private static void GetLogonErrorMessage(Exception exception, out string userMessage, out string adminMessage)
        {
            PSRemotingTransportException pSRemotingTransportException = exception as PSRemotingTransportException;

            if (pSRemotingTransportException == null)
            {
                PowwaException powwaException = exception as PowwaException;
                if (powwaException == null)
                {
                    ThreadAbortException threadAbortException = exception as ThreadAbortException;
                    if (threadAbortException == null)
                    {
                        userMessage = Resources.LogonError_UnknownError;
                        object[] message = new object[1];
                        message[0]   = exception.Message;
                        adminMessage = string.Format(CultureInfo.CurrentCulture, Resources.LogonError_UnknownErrorAdminMessage, message);
                        return;
                    }
                    else
                    {
                        string logonErrorThreadAborted = Resources.LogonError_ThreadAborted;
                        string str = logonErrorThreadAborted;
                        adminMessage = logonErrorThreadAborted;
                        userMessage  = str;
                        return;
                    }
                }
                else
                {
                    string message1 = powwaException.Message;
                    string str1     = message1;
                    adminMessage = message1;
                    userMessage  = str1;
                    return;
                }
            }
            else
            {
                int errorCode = pSRemotingTransportException.ErrorCode;
                if (errorCode > -2144108250)
                {
                    if (errorCode > 5)
                    {
                        if (errorCode == 53)
                        {
                            userMessage = Resources.LogonError_InvalidComputer;
                        }
                        else
                        {
                            if (errorCode == 0x51f)
                            {
                                userMessage = Resources.LogonError_NoLogonServers;
                            }
                            else
                            {
                                if (errorCode != 0x52e)
                                {
                                    goto Label0;
                                }
                                userMessage = Resources.LogonError_InvalidCredentials;
                            }
                        }
                    }
                    else
                    {
                        if (errorCode == -2144108126)
                        {
                            userMessage = Resources.LogonError_InvalidAuthenticationTypeCredSPP;
                        }
                        else
                        {
                            if (errorCode != 5)
                            {
                                goto Label0;
                            }
                            userMessage = Resources.LogonError_AccessDenied;
                        }
                    }
                }
                else
                {
                    if (errorCode > -2144108485)
                    {
                        if (errorCode == -2144108322)
                        {
                            userMessage = Resources.LogonError_InvalidAuthenticationTypeBasicOrDigest;
                        }
                        else
                        {
                            if (errorCode != -2144108250)
                            {
                                goto Label0;
                            }
                            userMessage = Resources.LogonError_InvalidEndpoint;
                        }
                    }
                    else
                    {
                        if (errorCode == -2144108526)
                        {
                            userMessage = Resources.LogonError_RemotingNotEnabled;
                        }
                        else
                        {
                            if (errorCode != -2144108485)
                            {
                                goto Label0;
                            }
                            userMessage = Resources.LogonError_InvalidConfigurationName;
                        }
                    }
                }
                adminMessage = pSRemotingTransportException.Message;
                return;
            }
Label0:
            if (((long)pSRemotingTransportException.ErrorCode & (long)-65536) != (long)-2144141312)
            {
                userMessage  = Resources.LogonError_ConnectionError;
                adminMessage = pSRemotingTransportException.Message;
                return;
            }
            else
            {
                object[] transportMessage = new object[1];
                transportMessage[0] = pSRemotingTransportException.TransportMessage;
                userMessage         = string.Format(CultureInfo.CurrentCulture, Resources.LogonError_ConnectionErrorExtended, transportMessage);
                adminMessage        = pSRemotingTransportException.Message;
                return;
            }
        }
Пример #24
0
        public TestOutcome Run(MarkupDocumentWriter markupDocumentWriter, Action action, string description)
        {
            // NOTE: This method has been optimized to minimize the total stack depth of the action
            //       by inlining blocks on the critical path that had previously been factored out.

            if (markupDocumentWriter == null)
            {
                throw new ArgumentNullException("markupDocumentWriter");
            }
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            ThreadAbortScope scope = null;

            try
            {
                lock (syncRoot)
                {
                    ThrowIfDisposed();

                    if (!abortOutcome.HasValue)
                    {
                        if (scopesAndThreads == null)
                        {
                            scopesAndThreads = new List <Pair <ThreadAbortScope, Thread> >();
                        }

                        scope = new ThreadAbortScope();
                        scopesAndThreads.Add(new Pair <ThreadAbortScope, Thread>(scope, Thread.CurrentThread));
                    }
                }

                if (scope == null)
                {
                    return(HandleAbort(markupDocumentWriter, description, null));
                }

                // Run the action within the scope we have acquired.
                try
                {
                    ThreadAbortException ex = scope.Run(action);
                    if (ex != null)
                    {
                        return(HandleAbort(markupDocumentWriter, description, ex));
                    }

                    return(TestOutcome.Passed);
                }
                catch (Exception ex)
                {
                    // If the test itself threw a thread abort, not because we aborted it
                    // ourselves but most likely due to a bug in the test subject, then we
                    // prevent the abort from bubbling up any further.
                    if (ex is ThreadAbortException &&
                        !AppDomain.CurrentDomain.IsFinalizingForUnload())
                    {
                        Thread.ResetAbort();
                    }

                    TestOutcome   outcome;
                    TestException testException = ex as TestException;
                    if (testException != null)
                    {
                        outcome = testException.Outcome;

                        if (testException.ExcludeStackTrace)
                        {
                            LogMessage(markupDocumentWriter, description, outcome, testException.HasNonDefaultMessage ? testException.Message : null, null);
                        }
                        else
                        {
                            LogMessage(markupDocumentWriter, description, outcome, null, testException);
                        }
                    }
                    else
                    {
                        outcome = TestOutcome.Failed;
                        LogMessage(markupDocumentWriter, description, outcome, null, ex);
                    }

                    return(outcome);
                }
            }
            finally
            {
                if (scope != null)
                {
                    lock (syncRoot)
                    {
                        if (scopesAndThreads != null)
                        {
                            for (int i = 0; i < scopesAndThreads.Count; i++)
                            {
                                if (scopesAndThreads[i].First == scope)
                                {
                                    scopesAndThreads.RemoveAt(i);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #25
0
        private TestOutcome HandleAbort(MarkupDocumentWriter markupDocumentWriter, string actionDescription, ThreadAbortException ex)
        {
            TestOutcome outcome = abortOutcome.Value;

            if (ex == null && alreadyLoggedAbortOnce)
            {
                return(outcome);
            }

            alreadyLoggedAbortOnce = true;
            LogMessage(markupDocumentWriter, actionDescription, outcome, abortMessage, null);
            return(outcome);
        }
        public override int Run(InterpretedFrame frame)
        {
            if (this._hasFinally)
            {
                frame.PushContinuation(base._labelIndex);
            }
            int instructionIndex = frame.InstructionIndex;

            frame.InstructionIndex++;
            Instruction[] instructions = frame.Interpreter.Instructions.Instructions;
            try
            {
                int index = frame.InstructionIndex;
                while ((index >= this._tryHandler.TryStartIndex) && (index < this._tryHandler.TryEndIndex))
                {
                    index += instructions[index].Run(frame);
                    frame.InstructionIndex = index;
                }
                if (index == this._tryHandler.GotoEndTargetIndex)
                {
                    frame.InstructionIndex += instructions[index].Run(frame);
                }
            }
            catch (RethrowException)
            {
                throw;
            }
            catch (Exception exception)
            {
                ExceptionHandler handler;
                frame.SaveTraceToException(exception);
                if (!this._tryHandler.IsCatchBlockExist)
                {
                    throw;
                }
                frame.InstructionIndex += this._tryHandler.GotoHandler(frame, exception, out handler);
                if (handler == null)
                {
                    throw;
                }
                ThreadAbortException exception2 = exception as ThreadAbortException;
                if (exception2 != null)
                {
                    System.Management.Automation.Interpreter.Interpreter.AnyAbortException = exception2;
                    frame.CurrentAbortHandler = handler;
                }
                bool flag = false;
                try
                {
                    int num3 = frame.InstructionIndex;
                    while ((num3 >= handler.HandlerStartIndex) && (num3 < handler.HandlerEndIndex))
                    {
                        num3 += instructions[num3].Run(frame);
                        frame.InstructionIndex = num3;
                    }
                    if (num3 == this._tryHandler.GotoEndTargetIndex)
                    {
                        frame.InstructionIndex += instructions[num3].Run(frame);
                    }
                }
                catch (RethrowException)
                {
                    flag = true;
                }
                if (flag)
                {
                    throw;
                }
            }
            finally
            {
                if (this._tryHandler.IsFinallyBlockExist)
                {
                    int num4 = frame.InstructionIndex = this._tryHandler.FinallyStartIndex;
                    while ((num4 >= this._tryHandler.FinallyStartIndex) && (num4 < this._tryHandler.FinallyEndIndex))
                    {
                        num4 += instructions[num4].Run(frame);
                        frame.InstructionIndex = num4;
                    }
                }
            }
            return(frame.InstructionIndex - instructionIndex);
        }
 /// <summary>
 ///		Handles a <see cref="ThreadAbortException"/> if it is thrown because hard execution timeout.
 /// </summary>
 /// <param name="mayBeHardTimeoutException">A <see cref="ThreadAbortException"/> if it may be thrown because hard execution timeout.</param>
 /// <exception cref="ArgumentNullException">
 ///		<paramref name="mayBeHardTimeoutException"/> is <c>null</c>.
 /// </exception>
 /// <exception cref="ThreadStateException">
 ///		<paramref name="mayBeHardTimeoutException"/> is not thrown on the current thread.
 /// </exception>
 protected internal void HandleThreadAbortException(ThreadAbortException mayBeHardTimeoutException)
 {
     this._runtime.HandleThreadAbortException(mayBeHardTimeoutException);
 }
        private static void Handler(object sender, UnhandledExceptionEventArgs args)
        {
            // Wrap it all in a try catch, so as not to generate any extra errors at this point
            try
            {
                // The information to display or log
                // Since "info" will be logged as well as displayed to the user in a message box, localize all
                //     strings connected to building "info" CRN
                string info;

                // Special case ThreadAbortExceptions during finalization
                ThreadAbortException tae = args.ExceptionObject as ThreadAbortException;
                if (tae != null)
                {
                    if (!args.IsTerminating)
                    {
                        return;
                    }
                }

                // Retrieve the exception object from the EventArgs
                Exception e = args.ExceptionObject as Exception;

                // Determine type of exception - CLS / Non-CLS
                if (e != null)
                {
                    // CLS-compliant - can access any Exception field (StackTrace, InnerException, etc.)
                    info = e.ToString();
                }
                else
                {
                    // Non-CLS compliant - can access methods defined by Object (ToString, GetType, etc.)
                    info = string.Format(CultureInfo.CurrentCulture, Strings.NonCLSCompliantException,
                                         args.ExceptionObject.GetType(), args.ExceptionObject.ToString());
                }

                // List type and string of Sender
                info += "\n\n" + string.Format(CultureInfo.CurrentCulture, Strings.SenderType, sender.GetType());
                info += "\n" + string.Format(CultureInfo.CurrentCulture, Strings.SenderString, sender.ToString());

                // Determine what type of thread caused the error
                info += "\n" + Strings.ThreadType + " ";
                if (!args.IsTerminating)
                {
                    info += Strings.PoolOrFinalizer;
                }
                else
                {
                    info += Strings.MainOrManual;
                }

                // Log version of product
                info += "\n" + string.Format(CultureInfo.CurrentCulture, Strings.ProductVersion,
                                             Application.ProductVersion.ToString());

                // Log it to the event log
                try
                {
                    EventLog eventLog = new EventLog("UnEx", ".", "MSR.LST.UnEx");
                    eventLog.WriteEntry(info, EventLogEntryType.Error, 999);
                }
                catch (Exception) {}

                // Compose message to user
                string msg = string.Format(CultureInfo.CurrentCulture, Strings.ErrorMessageToUser,
                                           AppDomain.CurrentDomain.FriendlyName, info);

                // Read user's preference from configuration file
                bool showMsg = true;
                if (ConfigurationManager.AppSettings[AppConfig.LST_ShowErrors] != null)
                {
                    showMsg = bool.Parse(ConfigurationManager.AppSettings[AppConfig.LST_ShowErrors]);
                }

                if (showMsg)
                {
                    RtlAwareMessageBox.Show(null, msg, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None,
                                            MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                }
            }
            catch (Exception) {}
        }
Пример #29
0
 void IThreadPoolWorkItem.MarkAborted(ThreadAbortException tae) /* nop */ }
Пример #30
0
        public static bool AbortedByKudu(this ThreadAbortException exception)
        {
            var state = exception?.ExceptionState as string;

            return(!String.IsNullOrEmpty(state) && state.StartsWith(KuduThreadAbortMessage, StringComparison.OrdinalIgnoreCase));
        }
Пример #31
0
 void IThreadPoolWorkItem.MarkAborted(ThreadAbortException tae) { /* nop */ }
Пример #32
0
        private void Work()
        {
            //Alive = true;
            while (true)
            {
                try
                {
                    //挂起自己,直到下一个任务到来
                    internalEvent.WaitOne(Timeout.Infinite, false);

                    Running = true;

                    //信号量复位
                    internalEvent.Reset();
                    if (Task != null)
                    {
                        ThreadTask task = Task;
                        WriteLog("新任务" + task.ID);
                        //task.Thread = this;
                        //WaitCallback method = Method;
                        //Object arg = Argument;
                        LastError = null;

                        StartTime = DateTime.Now;

                        //method(arg);
                        Task.Method(Task.Argument);
                    }
                }
                catch (ThreadInterruptedException ex)//中断异常,跳出
                {
                    LastError = ex;
                    Thread    = null;
                    internalEvent.Close();
                    internalEvent = null;
                    break;
                }
                catch (ThreadAbortException ex)//取消异常,有可能是终止当前任务而已,不需要跳出
                {
                    LastError = ex;

                    //异常参数指明是否需要终止线程
                    if (ex.ExceptionState != null && (Boolean)ex.ExceptionState)
                    {
                        Thread = null;
                        internalEvent.Close();
                        internalEvent = null;
                        break;
                    }
                }
                catch (Exception ex)//其它异常,继续
                {
                    LastError = ex;

                    ThreadAbortException e = FindException <ThreadAbortException>(ex);
                    //if (e == null)
                    //    XTrace.WriteException(ex);
                    //else
                    //{
                    //异常参数指明是否需要终止线程
                    if (e.ExceptionState != null && (Boolean)e.ExceptionState)
                    {
                        Thread = null;
                        internalEvent.Close();
                        internalEvent = null;
                        break;
                    }
                    //}
                }
                finally
                {
                    //通知事件订阅者,任务已经完成
                    if (_OnTaskFinished != null)
                    {
                        //对不信任方法的调用,捕获所有异常,防止因外部方法的错误而导致线程自身崩溃
                        try
                        {
                            _OnTaskFinished(this, EventArgs.Empty);
                        }
                        catch
                        {
                        }
                    }

                    //清空任务,防止下一次重复执行
                    Task = null;

                    AliveTime = DateTime.Now;

                    //不管怎么样,都要标志线程不再运行
                    Running = false;
                }
            }
            //Alive = false;
        }
Пример #33
0
 void IThreadPoolWorkItem.MarkAborted(ThreadAbortException exception)
 {
     if (!IsCompleted)
     {
         HandleException(exception);
         FinishThreadAbortedTask(true, false);
     }
 }