//-----------------------------------------------------------------------------// /// <summary> /// Look for function keys, etc. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TreeView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F10) { DirPerfStat.Instance().WriteResults(); } }
//-----------------------------------------------------------------------------// /// <summary> /// Run the high priority job in a separate thread. /// </summary> private void RunHighPriorityJob() { try { if (this.highPriorityJob != null) { IWorkUnit moreWork = null; try { moreWork = this.highPriorityJob.DoJob(); } finally { this.highPriorityJob = null; } if (moreWork != null) { this.AddJob(moreWork); } } } catch (System.Threading.ThreadAbortException) { DirPerfStat.Instance().IncrementHighPriorityThreadAborts(); } finally { this.highPriorityJob = null; this.highPriorityThread = null; } }
//-----------------------------------------------------------------------------// /// <summary> /// Singleton implementation /// </summary> /// <returns></returns> public static DirPerfStat Instance() { if (DirPerfStat.instance == null) { DirPerfStat.instance = new DirPerfStat(); } return(DirPerfStat.instance); }
//-----------------------------------------------------------------------------// /// <summary> /// Singleton implementation /// </summary> /// <returns></returns> public static DirPerfStat Instance() { if ( DirPerfStat.instance == null ) { DirPerfStat.instance = new DirPerfStat(); } return DirPerfStat.instance; }
//-----------------------------------------------------------------------------// /// <summary> /// Thread that runs a single low priority job. /// </summary> private void RunLowPriorityJob() { try { this.moreWorkToDoFromThread = this.currentNormalJob.DoJob(); } catch (System.Threading.ThreadAbortException) { DirPerfStat.Instance().IncrementLowPriorityThreadAborts(); } finally { this.lowPriorityThread = null; } }
//-----------------------------------------------------------------------------// /// <summary> /// job one, load the sub-dirs, and set as complete, if there are sub-dirs /// return "this" to perform the Job 2 Pass. /// </summary> /// <returns></returns> private IWorkUnit DoJobOne() { IWorkUnit moreWork = null; try { // See if we're refreshing. if (this.folderNode.Nodes.Count > 0 && this.folderNode.Stale) { try { this.guiFlagger.SignalBeginGUI(); this.form.MainForm.Invoke(new InvokeDelegate(this.ClearNode)); } finally { this.guiFlagger.SignalEndGUI(); } this.folderNode.Stale = false; } if (this.folderNode.Nodes.Count == 0 && !this.stop) { this.subDirs = null; this.subDirs = DirPerfStat.Instance().GetDirectories(this.folderNode.DirInfo); if (this.subDirs == null) { this.YouWereAborted(); } if (this.subDirs != null && this.subDirs.Length > 0 && !this.stop) { try { this.guiFlagger.SignalBeginGUI(); this.form.MainForm.Invoke(new InvokeDelegate(this.AddSubNodes)); } finally { this.guiFlagger.SignalEndGUI(); } // We did something, so there's more work to be done. moreWork = this; } } else { moreWork = this; } } finally { this.subDirs = null; this.jobOneComplete = true; } return(moreWork); }
//-----------------------------------------------------------------------------// /// <summary> /// Go through each sub-folder and load it's sub-folders. /// </summary> /// <returns></returns> private IWorkUnit DoJobTwo() { try { foreach (KExplorerNode sNode in this.folderNode.Nodes) { if (this.stop) { break; } this.currentSubFolderNode = sNode; if (sNode.Nodes.Count > 0 && sNode.Stale) { try { this.guiFlagger.SignalBeginGUI(); this.form.MainForm.Invoke(new InvokeDelegate(this.ClearSubNode)); } finally { this.guiFlagger.SignalEndGUI(); } sNode.Stale = false; } if (sNode.Nodes.Count == 0) { try { this.subDirs = null; this.subDirs = DirPerfStat.Instance().GetDirectories(sNode.DirInfo); if (this.subDirs == null) { this.YouWereAborted(); } if (this.subDirs != null && this.subDirs.Length > 0 && !this.stop) { try { this.guiFlagger.SignalBeginGUI(); this.form.MainForm.Invoke(new InvokeDelegate(this.AddSubSubNodes)); } finally { this.guiFlagger.SignalEndGUI(); } } } catch (Exception) { } } } } finally { this.subDirs = null; this.currentSubFolderNode = null; } return(null); }
//------------------------------------------------------------------------------- /// <summary> /// Start the job. /// </summary> /// <returns></returns> public IWorkUnit DoJob() { this.table = new DataTable("Files"); DataColumn c = null; c = new DataColumn(); c.DataType = System.Type.GetType("System.IO.FileInfo"); c.ColumnName = "Name"; c.ReadOnly = true; c.Unique = true; table.Columns.Add(c); c = new DataColumn(); c.DataType = System.Type.GetType("System.String"); c.ColumnName = "Ext"; c.ReadOnly = true; c.Unique = false; table.Columns.Add(c); c = new DataColumn(); c.DataType = System.Type.GetType("System.Int64"); c.ColumnName = "Size"; c.ReadOnly = true; c.Unique = false; table.Columns.Add(c); c = new DataColumn(); c.DataType = System.Type.GetType("System.String"); c.ColumnName = "Attrib"; c.ReadOnly = true; c.Unique = false; table.Columns.Add(c); c = new DataColumn(); c.DataType = System.Type.GetType("System.DateTime"); c.ColumnName = "LastUpdate"; c.ReadOnly = true; c.Unique = false; table.Columns.Add(c); c = new DataColumn(); c.DataType = System.Type.GetType("System.String"); c.ColumnName = "UpdTime"; c.ReadOnly = true; c.Unique = false; table.Columns.Add(c); try { FileInfo[] files = DirPerfStat.Instance().GetFiles(this.kNode.DirInfo); foreach (FileInfo file in files) { if (this.stop) { return(null); } DataRow row = this.table.NewRow(); row["Name"] = file; row["LastUpdate"] = file.LastWriteTime; row["Ext"] = file.Extension; row["Size"] = file.Length; row["Attrib"] = file.Attributes.ToString(); row["UpdTime"] = file.LastWriteTime.TimeOfDay.ToString(); this.table.Rows.Add(row); } if (this.stop) { return(null); } } catch (Exception) { } // Insert code to create and populate columns. this.view = new DataView(table); if (!this.stop) { this.kForm.MainForm.Invoke(new InvokeDelegate(this.SetDataToDataGrid)); } return(null); }