-1

In our program, the splash screen is used in a separate thread. When the main thread finishes some jobs, it aborts the splash thread.

Here is the code:

if (thread != null && thread.IsAlive)
   {
     try
     {
       thread.Abort();
     }
     catch (ThreadAbortException)
     {
       Debug.WriteLine("Splash thread aborted");
     }
   }

When used in a local or network computer, it works just fine.

When used in a terminal server, we get this exception:

System.Threading.ThreadAbortException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Thread was being aborted.

Stack trace:

System.ServiceModel.Diagnostics.DiagnosticTrace.UnhandledExceptionHandler(Object sender, UnhandledExceptionEventArgs args)
MS.Win32.UnsafeNativeMethods.ITfMessagePump.GetMessageW(MSG& msg, Int32 hwnd, Int32 msgFilterMin, Int32 msgFilterMax, Boolean& result)
System.Windows.Threading.Dispatcher.GetMessage(MSG& msg, IntPtr hwnd, Int32 minMessage, Int32 maxMessage)
System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
System.Windows.Window.ShowHelper(Object booleanBox)
System.Windows.Window.Show()
System.Windows.Window.ShowDialog()
OurApplication.App.<>c__DisplayClass8.<Application_Startup>b__0()
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
System.Threading.ThreadHelper.ThreadStart()

The Trace shows this as an Unhandled Exception, yet it uses a catch. It raises the question if its running on a terminal server has something to do with it.

Does a terminal server create a special context that handles threads differently?

Nestor
  • 8,194
  • 7
  • 77
  • 156
  • 7
    You should send a signal to your splash screen thread to end itself. Don't abort threads if you don't have to. – nvoigt Dec 19 '14 at 09:16
  • you are doing it wrong: you should have an applicationContext and open the splash as a form and then close it. if you abort a thread you get the threadabortexception – giammin Dec 19 '14 at 09:16
  • 2
    If it hurts, don't do it. [My very very very recent answer](http://stackoverflow.com/questions/27561976/check-if-thread-finished-its-method-before-killing-it-c-sharp/27562048#27562048). Just stop the message loop if the thread runs one, Call `Close` on your splash screen form, but you should marshal the call to its owner thread. You do it by calling `Control.Invoke` . – Sriram Sakthivel Dec 19 '14 at 09:16

1 Answers1

0

It seems that the terminal server context handles this type of exception differently (it may have a sensitive setting for detecting any type of exceptions).

Eventually, I eliminated the thread abort and used an event-based approach. It works now on the local machines and on the terminate servers as well.

Nestor
  • 8,194
  • 7
  • 77
  • 156