Exemplo n.º 1
0
        /// <summary>
        /// Called when closing the application. This will ensure all SCHOTT threads
        /// that were added to the worker are closed before returning.
        /// </summary>
        /// <returns>True when threads are shut down, false when still closing threads.</returns>
        public ClosingInfo ShutdownThreads()
        {
            var closingInfo = new ClosingInfo();

            // check all the threaded classes
            closingInfo.ChildInfo.Clear();
            foreach (var o in _threadedItemsToClose)
            {
                closingInfo.ChildInfo.Add(o.ShutdownReady());
            }

            // update ClosingInfo
            if (closingInfo.ChildInfo.Any(x => x.ShutdownReady == false))
            {
                // we have children still waiting
                closingInfo.ShutdownReady = false;
                foreach (var info in closingInfo.ChildInfo.Where(x => x.ShutdownReady == false))
                {
                    if (closingInfo.Message.Length > 0)
                    {
                        closingInfo.Message += $"{Environment.NewLine}{Environment.NewLine}";
                    }

                    closingInfo.Message += $"{info.Message}";
                }
            }
            else
            {
                closingInfo.ShutdownReady = true;
            }

            RunStatusUpdate(closingInfo.Message);
            return(closingInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get shutdown status
        /// </summary>
        /// <returns>ClosingInfo for this thread and all children</returns>
        public virtual ClosingInfo ShutdownReady()
        {
            var closingInfo = new ClosingInfo();

            // poke each thread then see if it is complete
            AddDerivedClosingInfoChildren(closingInfo);
            foreach (var info in WorkerThreads)
            {
                closingInfo.ChildInfo.Add(info.ShutdownReady());
            }

            // update ClosingInfo
            if (closingInfo.ChildInfo.Any(x => x.ShutdownReady == false))
            {
                // we have children still waiting
                closingInfo.Message       = ThreadInfo.MessageStatus($"Closing Thread ({ThreadName}): Waiting", ApplicationClosingCount++);
                closingInfo.ShutdownReady = false;
                foreach (var info in closingInfo.ChildInfo.Where(x => x.ShutdownReady == false))
                {
                    closingInfo.Message += $"{Environment.NewLine}  {info.Message.Replace(Environment.NewLine, $"{Environment.NewLine}  ")}";
                }
            }
            else
            {
                closingInfo.Message       = $"Closing Thread ({ThreadName}): Done!";
                closingInfo.ShutdownReady = true;
            }

            // return readiness to shutdown
            return(closingInfo);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Function to begin shutting down the thread and query the status.
        /// </summary>
        /// <returns>True = StateMachine is finished and thread is closed, False otherwise.</returns>
        public ClosingInfo ShutdownReady()
        {
            var closingInfo = new ClosingInfo();

            if (Thread.ThreadState != ThreadState.Stopped)
            {
                CloseThread = true;
                WaitHandle.Set();
                closingInfo.Message       = MessageStatus($"Closing Thread ({ThreadName}): Waiting", _applicationClosingCount++);
                closingInfo.ShutdownReady = false;
                return(closingInfo);
            }

            closingInfo.Message       = $"Closing Thread ({ThreadName}): Done!";
            closingInfo.ShutdownReady = true;
            return(closingInfo);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Function to be overridden by derived classes. Processing of data should be done here.
 /// </summary>
 /// <param name="closingInfo">The closing info object to add children too.</param>
 protected virtual void AddDerivedClosingInfoChildren(ClosingInfo closingInfo)
 {
 }