/// <summary> /// Removes a thread from the tracker. /// </summary> /// <param name="p_ttdThread">The thread that was tracked.</param> public static void RemoveThread(TrackedThread p_ttdThread) { lock (m_objLock) { m_lstTrackedThreads.Remove(p_ttdThread); } }
/// <summary> /// Adds a thread to the tracker. /// </summary> /// <param name="p_ttdThread">The thread to be tracked.</param> public static void AddThread(TrackedThread p_ttdThread) { lock (m_objLock) { if (!m_lstTrackedThreads.Contains(p_ttdThread)) m_lstTrackedThreads.Add(p_ttdThread); } }
/// <summary> /// Adds a thread to the tracker. /// </summary> /// <param name="p_ttdThread">The thread to be tracked.</param> public static void AddThread(TrackedThread p_ttdThread) { lock (m_objLock) { if (!m_lstTrackedThreads.Contains(p_ttdThread)) { m_lstTrackedThreads.Add(p_ttdThread); } } }
/// <summary> /// Starts the task, optionally in a background thread. /// </summary> /// <remarks> /// If the task is started in a background thread, the task will be terminated in the /// calling thread terminates. Otherwise, the calling thread will not terminate until /// the task completes. /// </remarks> /// <param name="p_booRunInBackground">Whether the task should be run in a background thread.</param> /// <param name="p_objArgs">Arguments to pass to the task execution method.</param> /// <seealso cref="Start(object[])"/> /// <seealso cref="StartWait(object[])"/> /// <seealso cref="StartWait(bool, object[])"/> protected void Start(bool p_booRunInBackground, params object[] p_objArgs) { //Not sure if BeginInvoke/EndInvoke or Thread is better for exception handling // it seem BeginInvoke/EndInvoke is not ideal. exceptions are trapped and rethrown // in EndThreadInvokeHandler when EnInvoke is called, so the debugger // breaks in EndThreadInvokeHandler, and not where the exception is actually thrown //however, I was using threads here, and I changed. according the the SVN log, I made // the switch to improve exception handling. not sure what issue I was encountering. // maybe the issue was actually related to the fact that some operations at the time // were wrapped in unneccessary threads - that issue has since been resolved // //I would like to find, and then document, a specific case where the thread // provides an advantage over BeginInvoke/EndInvoke. in StartWait(), // I seem to be observing the debugger break on the source of the exception, even // with BeginInvoke/EndInvoke, so I would like a conter-example. //example of BeginInvoke/EndInvoke breaking on exception source: if I insert: // if (System.Windows.Forms.MessageBox.Show("Now?", "CRASH", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) // throw new DirectoryNotFoundException("DUMMY"); // as the first line of Archive.public byte[] GetFileContents(string p_strPath) // StartWait() breaks on said line. /*Func<object, object> dlg = new Func<object, object>(RunThreadedWork); IAsyncResult ar = dlg.BeginInvoke(p_objArgs, EndThreadInvokeHandler, p_objArgs);*/ TrackedThread thdWork = new TrackedThread(RunThread); thdWork.Thread.IsBackground = p_booRunInBackground; thdWork.Start(p_objArgs); }
/// <summary> /// Starts the file download. /// </summary> /// <remarks> /// After a block has finished downloading, a new block will be requested for download. /// this will continue until no blocks are left, or told to stop. /// </remarks> public void Start() { Finished = false; TrackedThread thdDownloader = new TrackedThread(DoStart); thdDownloader.Thread.Name = String.Format("Block Dldr @ {0}", DateTime.Now); thdDownloader.Start(); }
/// <summary> /// Installs the mod. /// </summary> public void Install() { TrackedThread thdWorker = new TrackedThread(RunTasks); thdWorker.Thread.IsBackground = false; thdWorker.Start(); }
/// <summary> /// Uninstalls the mod. /// </summary> public void Install() { if (!ModInstallLog.ActiveMods.Contains(Mod)) { OnTaskSetCompleted(true, "The mod was successfully deactivated.", Mod); return; } TrackedThread thdWorker = new TrackedThread(RunTasks); thdWorker.Thread.IsBackground = false; thdWorker.Start(); }
/// <summary> /// Initializes the thread safe extractor. /// </summary> protected void Init() { m_queEvents = new Queue<ActionPackage>(); m_mreEvent = new ManualResetEvent(false); m_thdExtractor = new TrackedThread(RunThread); m_thdExtractor.Thread.IsBackground = false; m_thdExtractor.Thread.Name = "Seven Zip Extractor"; ActionPackage apkStart = new ActionPackage(null); m_queEvents.Enqueue(apkStart); m_thdExtractor.Start(); apkStart.DoneEvent.WaitOne(); }