Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had an application designed in WPF on VS2008 using Windows 7 32-bit machine and deployed on Windows XP. Tested and everything worked fine.

Recently, some cosmetic and business logic changes were required. This time I used VS2010 and made the required changes. Tested and deployed on Windows XP everything works fine. However when deployed on Windows 7 32-bit, the application crashes.

After looking at the logs, I narrowed it down to this probably piece of code :

C#
protected virtual void SomeEventHandlerMethod()
        {
            try
            {
                System.Windows.Application.Current.Dispatcher.Invoke(
                      DispatcherPriority.Normal,
                      new Action<Data>(FollowMethod), new dData(SubTypeData));
            }
            catch (Exception ex)
            {
                Logger.ErrorException(ex.Message, ex);
            }
        }


Following is the stack trace of the exception thrown :

System.Threading.ThreadAbortException: Thread was being aborted.

at System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)

at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext)

at System.Threading.WaitHandle.WaitOne(TimeSpan timeout, Boolean exitContext)

at System.Windows.Threading.DispatcherOperation.DispatcherOperationEvent.WaitOne()

at System.Windows.Threading.DispatcherOperation.Wait(TimeSpan timeout)

at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

at Fully Qualified name of the method SomeEventHandlerMethod()


I am not able to figure out the reason of the application crash when running on Windows 7. I MUST figure this out. HELP!
Posted
Comments
Sergey Alexandrovich Kryukov 23-Jan-12 15:08pm    
Did you call Thread.Abort anywhere?
--SA

1 solution

You did not provide relevant code here. So, I'll just give you an idea. The exception ThreadAbortException is nothing like an error condition. This exception should be caught on the very top of stack of any thread which is aborted using Thread.Abort or it there is a possibility of abort. The exception is used to perform the post-mortal action of a thread, proper clean-up.

The technique using abort and this exception is one of the techniques of thread termination. It is designed to provide termination with zero overhead, without any cost of cooperation from the thread side. It is critically important in some applications where the condition of termination is uncertain, to a thread needs to be terminated by another thread. This mechanism is very reliable, but only if you know very well what happens to your thread, understand the mechanisms very well and write the thread code with great care.

—SA
 
Share this answer
 
Comments
that143guy@yahoo.com 23-Jan-12 20:51pm    
Hey SA!

Appreciate your help.
I don't think I am calling any Thread.Abort anywhere.
Also, the code which I mentioned above is pretty much the exact code where the stack trace takes me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900