// // - Constructors - // /// <summary> /// Default coonstructor. /// </summary> public ThreadManager() { this.childThreads = new ThreadCollection(); this.threads = new ThreadCollection(); threadStatesCount[(int)ThreadState.UnStarted] = 0; threadStatesCount[(int)ThreadState.Running] = 0; threadStatesCount[(int)ThreadState.Stopping] = 0; threadStatesCount[(int)ThreadState.Stopped] = 0; }
/// <summary> /// Initializes this instance. /// </summary> /// <remarks> /// Call one of the Initialize methods directly after creating a Thread instance. /// /// Code that normally would be present in the constructor. /// This code is however put in a separate method to be able to have only /// one constructor in DicomThread. This way, it is easier to derive from a /// DicomThread class. /// /// Use this method if this threads should not have a parent thread. /// </remarks> /// <param name="threadManager">The ThreadManager that manages this object.</param> protected void Initialize(ThreadManager threadManager) { this.parent = null; this.dotNetThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.ThreadEntryPoint)); this.threadManager = threadManager; this.topmostThread = this; // See property ThreadManagerLock when to use this lock. lock (this.threadManager.ThreadManagerLock) { this.childs = new ThreadCollection(); this.threadManager.ChildThreads.Add(this); this.threadManager.AddChildThread(this); } }
/// <summary> /// Initializes this instance. /// </summary> /// <remarks> /// Call one of the Initialize methods directly after creating a Thread instance. /// /// Code that normally would be present in the constructor. /// This code is however put in a separate method to be able to have only /// one constructor in DicomThread. This way, it is easier to derive from a /// DicomThread class. /// /// Use this method if this object should have a parent thread. /// </remarks> /// <param name="parent">The parent Thread.</param> protected void Initialize(Thread parent) { this.parent = parent; this.dotNetThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.ThreadEntryPoint)); this.threadManager = this.parent.ThreadManager; this.topmostThread = this.parent.TopmostThread; // See property ThreadManagerLock when to use this lock. lock (this.threadManager.ThreadManagerLock) { this.childs = new ThreadCollection(); this.parent.childs.Add(this); this.threadManager.AddThread(this); } if (this.parent.ThreadOptions.AttachChildsToUserInterfaces) { foreach (IThreadUserInterface threadUserInterface in this.parent.AttachedUserInterfaces) { threadUserInterface.Attach(this); } } }