Shutdown order proposal

I generally have very good reliability with SGP running through the ASCOM driver for TheSkyX. On rare occasions SGP is unable to park the mount and close the roof on shutdown. I had one such last night.

The ASCOM driver is limited by the TSX API and it can get confused if multiple commands are hitting it at the same time (probably a sync/async thing, but I am no expert).

Looking at the log files, SGP sent the ASCOM park command before trying to stop PHD2 guiding (direct guide method through ASCOM). I think in some instances, conflicting commands from both cause the park command to issue an exception. The TSX ASCOM driver was otherwise fine, since I was able to manually close the roof later on, through another application, connected to the same ASCOM driver… so it does not appear to be the case that the ASCOM driver dynamically disabled its options due to exceptions from the API.

It might help if the guider is stopped before trying to issue the park command. I cannot see the harm in it.
Log snippit.

[03/17/20 04:14:07.720][DEBUG][Telescope Thread][SQ;PK;] ASCOM Telescope: Sending park…
[03/17/20 04:14:07.770][DEBUG][Telescope Thread][SQ;PK;] ASCOM Telescope: Error in ParkTel! : CheckDotNetExceptions ASCOM.SoftwareBisque.Telescope Park System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at System.Runtime.InteropServices.Marshal.GetIDispatchForObjectNative(Object o, Boolean onlyInContext)
at CallSite.Target(Closure , CallSite , ComObject )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0](CallSite site, T0 arg0)
at ASCOM.SoftwareBisque.Telescope.Park() (See Inner Exception for details) (System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at System.Runtime.InteropServices.Marshal.GetIDispatchForObjectNative(Object o, Boolean onlyInContext)
at CallSite.Target(Closure , CallSite , ComObject )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0](CallSite site, T0 arg0)
at ASCOM.SoftwareBisque.Telescope.Park())
at ASCOM.DriverAccess.MemberFactory.CheckDotNetExceptions(String memberName, Exception e) in C:\ASCOM Build\Export\ASCOM.DriverAccess\MemberFactory.cs:line 630
at ASCOM.DriverAccess.MemberFactory.MethodTargetInvocationExceptionHandler(String memberName, Exception e) in C:\ASCOM Build\Export\ASCOM.DriverAccess\MemberFactory.cs:line 678
at ASCOM.DriverAccess.MemberFactory.CallMember(Int32 memberCode, String memberName, Type[] parameterTypes, Object[] parms) in C:\ASCOM Build\Export\ASCOM.DriverAccess\MemberFactory.cs:line 422
at ASCOM.DriverAccess.Telescope.Park() in C:\ASCOM Build\Export\ASCOM.DriverAccess\Telescope.cs:line 728
at r6.cf(String& A_0)
[03/17/20 04:14:07.770][DEBUG][Telescope Thread][SQ;PK;] Error parking scope, aborting observatory options, cannot verify scope position…
[03/17/20 04:14:07.770][ERROR][Telescope Thread][SQ;PK;] Error parking telescope: Error in Parking Telescope! See logs.
[03/17/20 04:14:07.771][INFO][Telescope Thread][SQ;PK;] Attempting to emergency stop mount and observatory…
[03/17/20 04:14:07.776][DEBUG][Telescope Thread][SQ;PK;] Sending Notification: Error - Mount park has failed! Emergency stop issued to mount and observatory.
[03/17/20 04:14:07.776][DEBUG][Telescope Thread][SQ;PK;] ASCOM Telescope: Setting tracking state to False
[03/17/20 04:14:07.777][DEBUG][Telescope Thread][SQ;PK;] ASCOM Telescope: Cannot set tracking state, not supported by scope…
[03/17/20 04:14:07.780][DEBUG][Telescope Thread][SQ;PK;] Attempting to stop PHD2 guiding…
[03/17/20 04:14:07.780][DEBUG][Telescope Thread][SQ;PK;] Checking PHD2 state…
[03/17/20 04:14:07.780][DEBUG][Telescope Thread][SQ;PK;] PHD2 GetPhdStatus - Pre-Wait : Stopped
[03/17/20 04:14:07.780][DEBUG][Telescope Thread][SQ;PK;] Sending to PHD2: