Exemple #1
0
        /// <summary>
        /// Remove the provided script from the script system.
        /// </summary>
        /// <param name="script">The script to remove</param>
        public void Remove(ScriptComponent script)
        {
            // Make sure it's not registered in any pending list
            var startWasPending = scriptsToStart.Remove(script);
            var wasRegistered   = registeredScripts.Remove(script);

            if (!startWasPending && wasRegistered)
            {
                // Cancel scripts that were already started
                try
                {
                    script.Cancel();
                }
                catch (Exception e)
                {
                    HandleSynchronousException(script, e);
                }

                var asyncScript = script as AsyncScript;
                asyncScript?.MicroThread.Cancel();
            }

            var syncScript = script as SyncScript;

            if (syncScript != null)
            {
                syncScripts.Remove(syncScript);
                syncScript.UpdateSchedulerNode = null;
            }
        }
Exemple #2
0
        /// <summary>
        /// Remove the provided script from the script system.
        /// </summary>
        /// <param name="script">The script to remove</param>
        public void Remove(ScriptComponent script)
        {
            // Make sure it's not registered in any pending list
            var startWasPending = scriptsToStart.Remove(script);
            var wasRegistered   = registeredScripts.Remove(script);

            if (!startWasPending && wasRegistered)
            {
                // Cancel scripts that were already started
                try
                {
                    script.Cancel();
                }
                catch (Exception e)
                {
                    HandleSynchronousException(script, e);
                }

                var asyncScript = script as AsyncScript;
                asyncScript?.MicroThread.Cancel();
            }

            // Remove script from the scheduler, in case it was removed during scheduler execution
            var startupScript = script as StartupScript;

            if (startupScript != null)
            {
                if (startupScript.StartSchedulerNode != null)
                {
                    Scheduler?.Unschedule(startupScript.StartSchedulerNode);
                    startupScript.StartSchedulerNode = null;
                }

                var syncScript = script as SyncScript;
                if (syncScript != null)
                {
                    syncScripts.Remove(syncScript);
                    Scheduler?.Unschedule(syncScript.UpdateSchedulerNode);
                    syncScript.UpdateSchedulerNode = null;
                }
            }
        }