Upgraded to 2.2.2.7850. Now Receiving ThreadAbortException

Bug reports.
User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Upgraded to 2.2.2.7850. Now Receiving ThreadAbortException

Post by Ciege » Mon Mar 15, 2010 11:28 pm

I have been running quite well for sometime using version 2.1.4.6779. I have just upgraded to version 2.2.2.7850. I am now "randomly" receiving the following exception. It seems to only occur when I call my WaitForWindow method AND the Window does not appear within the timeout (which is a perfectly acceptible situation in my case since I often times need to check that an attention dialog or process working dialog is gone before continuing my script and in some cases it may disappear before I even get a chance to find it).

Code: Select all

System.Threading.ThreadAbortException: Thread was being aborted.
at RanorexFramework.RFW.WaitForWindow(String WindowName, Int32 Timeout) in C:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\RanorexFramework\RanorexFramework\Class1.cs:line 5085
at RanorexFramework.RFW.ReportPrint(Form HDReportsForm, ReportPrintOptions MyReportPrintOptions, Boolean boolCloseReportsDialog) in C:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\RanorexFramework\RanorexFramework\Class1.cs:line 9155
See below for line 5085:

Code: Select all

        public static Ranorex.Form WaitForWindow(string WindowName, int Timeout)
        {
            Ranorex.Form HDForm = null;

            Report.Debug("Waiting for window: " + WindowName);
            try
            {
                HDForm = Host.Local.FindSingle("/form[@title='" + WindowName + "' or @controlname='" + WindowName + "']", Timeout * 1000);
                HDForm.Activate();
                Thread.Sleep(1000);
                return HDForm;
            }
            catch (RanorexException e)
            {
                try
                {
                    Thread.Sleep(5000);
                    HDForm = Host.Local.FindSingle("/form[@title='" + WindowName + "' or @controlname='" + WindowName + "']", (Timeout * 2) * 1000);
                    HDForm.Activate();
                    Thread.Sleep(1000);
                    return HDForm;
                }
                catch (RanorexException ex)
                {
                    Report.Debug("Unable to find window: " + WindowName);
                    return null;   //THIS IS LINE 5085
                }
            }
        } //End WaitForWindow

See below for line 9155:

Code: Select all

Ranorex.Form HDGeneratingReport = RFW.WaitForWindow("ProgressBarForm", 4);

I have two threads running in my automation tests. The first, main thread is the main testing thread and is marked with STAThread.
The second thread is created by the main thread to check for unhandled exceptions that may be thrown by the AUT. You guys there helped me write this one.

Code: Select all

    public class Worker
    {
        Thread mainThread = null;

        public Thread MainThread
        {
            set { mainThread = value; }
        }

        [STAThread]
        public void ThreadTask()
        {
            try
            {
                int i = 0;
                while (i == 0)
                {
                    foreach (Ranorex.Form form in Host.Local.Find<Ranorex.Form>("/form[@title='Unhandled Application Thread Exception']"))
                    {
                        if (form.Visible && form.Enabled)
                        {
                            //Found Exception 
                            Report.Failure("AUT Unhandled Application Thread Exception Detected.");
                            Report.Failure("Stopping all test threads.");
                            Report.Screenshot();
                            i++;
                        }
                    }
                    foreach (Ranorex.Form form in Host.Local.Find<Ranorex.Form>("/form[@title~'MainInterface.exe - Application Error']"))
                    {
                        if (form.Visible && form.Enabled)
                        {
                            //Found Exception 
                            Report.Failure("Application Error Detected.");
                            Report.Failure("Stopping all test threads.");
                            Report.Screenshot();
                            i++;
                        }
                    }
                    Thread.Sleep(1000);
                }

                //Throw Exception to the Main Thread
                if (mainThread != null)
                    mainThread.Abort("SUTAbort");
            }
            catch
            {
            }
        }
    }
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Upgraded to 2.2.2.7850. Now Receiving ThreadAbortException

Post by Ciege » Mon Mar 15, 2010 11:32 pm

Forgot to add the code that starts the second thread:

Code: Select all

        [STAThread]
        static void Main(string[] args)
        {
            Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;

            // Setup Reporter   
            //<...>

            try
            {
                Host.Local.FindChildren<Ranorex.Form>();

                Report.Info("*******************************");
                Report.Info("Main thread: Starting worker thread checking for AUT Unhandled Exceptions...");
                Report.Info("*******************************");
                Report.Info("");

                // Create the thread object. This does not start the thread.
                Worker workerObject = new Worker();
                workerObject.MainThread = Thread.CurrentThread;
                Thread workerThread = new Thread(workerObject.ThreadTask);

                // Start the worker thread.
                workerThread.SetApartmentState(ApartmentState.STA);
                workerThread.IsBackground = true;
                workerThread.Start();

                int intResult = 0;

                //Setup Defaults
                Mouse.DefaultMoveTime = 0;
                Keyboard.DefaultKeyPressTime = 2;

                //Start Regression Tests
                intResult = StartReportsTests(strDateTimeStamp);
                if (intResult == 0)
                {
                    Report.Success("Reports Test Competed.");
                }
                else
                {
                    Report.Failure("Error occured during Reports Test.");
                    Report.Screenshot();
                }

                workerThread.Abort();
            }
            catch (RanorexException e)
            {
                Report.Error(e.ToString());
                Report.Screenshot();
            }
            catch (ThreadAbortException ex)
            {
                if (ex.ExceptionState.Equals("SUTAbort"))
                    Report.End();

                Thread.ResetAbort();
            }
            catch (Exception ex)
            {
                Report.Failure("Fatal error: " + ex.ToString());
                Report.Screenshot();
                MessageBox.Show("FATAL ERROR: " + ex.ToString());
            }

            //Close the Reporter & End
            Report.End();
            System.Diagnostics.Process.Start("iexplore.exe", LogFile);
            return;
        }
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Upgraded to 2.2.2.7850. Now Receiving ThreadAbortException

Post by Support Team » Wed Mar 17, 2010 5:28 pm

Several customers reported that bug with Ranorex 2.2.X versions. We have already implemented a fix for that bug and tested it with several customers (including ciege :) ) - until now, the fix looks promising. So we will integrate that fix in the next released version!

Regards,
Alex
Ranorex Support Team
.
Image

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Upgraded to 2.2.2.7850. Now Receiving ThreadAbortException

Post by Ciege » Wed Mar 17, 2010 5:50 pm

Indeed... I have tested the fix and it appears to run correctly for me.

Thank you guys for the very fast turnaround on this! Your dedication to us, the end users, is awesome!
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...