private void button1_Click(object sender, EventArgs e) { if (IsWorking) { if (workControl.IsRunning) { workControl.NeedStop = true; } /*workerThread.Join(); * * TimeSpan tsS = TimeSpan.Zero; * TimeSpan tsC = TimeSpan.Zero; * * if (workerThreadParam != null) * { * tsS = workerThreadParam.timeScan; * tsC = workerThreadParam.timeCompare; * } * * StopWorking(tsS, tsC);*/ } else { workerThreadParam = new DoCollectInfoParam(this); if (!string.IsNullOrWhiteSpace(textBox4.Text)) { IsWorking = true; /*workerThread = new Thread(DoCollectInfo); * * workerThread.Start(workerThreadParam);*/ backgroundWorker1.RunWorkerAsync(); } else { label8.Text = "Database file name not specified"; } } }
private static void DoCollectInfo(object data) { DoCollectInfoParam p = (DoCollectInfoParam)data; if (!string.IsNullOrEmpty(p.db1)) { //bool bOpS = false; string sDb = p.db1; string sDbe = sDb; if (sDbe.EndsWith(REPORT_FILE_EXT, StringComparison.CurrentCultureIgnoreCase)) { sDb = sDb.Substring(0, sDb.Length - REPORT_FILE_EXT.Length); } else { sDbe += REPORT_FILE_EXT; } //p.timeScan = TimeSpan.Zero; XmlDocument xDoc = null; DirectoryInfoDatabaseComparable di = new DirectoryInfoDatabaseComparable(p.workControl); if (!string.IsNullOrEmpty(p.path)) { di.FileMask = p.mask; di.m_bLowerCaseNames = p.useLowerCase; di.Comment = p.comment; di.m_bTimeInTicks = p.useTicks; di.m_bOnlyCorrupted = p.onlyCorrupted; di.ExcludedCompany = p.excludedCompany; di.m_bExcludeEmptyDirs = p.excludeEmptyFolders; di.m_bTryToFixCorruptedFiles = p.tryToFixCorruptedFiles; di.m_sDriverFolder = p.driverFolder; xDoc = di.CollectInfo(p.path, p.depth); if (xDoc != null) { if (p.excludeEmptyFolders) { xDoc = DirectoryInfoDatabaseComparable.RemoveEmptyDirectories(xDoc); } DirectoryInfoDatabaseComparable.Save(xDoc, sDbe); string t1s = xDoc.DocumentElement.GetAttribute(DirectoryInfoDatabaseComparable.XML_ELEMENT_ROOT_ATTRIBUTE_STARTTIME); string t2s = xDoc.DocumentElement.GetAttribute(DirectoryInfoDatabaseComparable.XML_ELEMENT_ROOT_ATTRIBUTE_ENDTIME); long t1l, t2l; if (long.TryParse(t1s, out t1l) && long.TryParse(t2s, out t2l)) { p.timeScan = new TimeSpan(t2l - t1l); //bOpS = true; } else { DateTime t1, t2; if (DateTime.TryParse(t1s, out t1) && DateTime.TryParse(t2s, out t2)) { p.timeScan = t2 - t1; //bOpS = true; } } } } //bool bOpC = false; //p.timeCompare = TimeSpan.Zero; if (!string.IsNullOrEmpty(p.db2)) { string sDb2 = p.db2; string sDb2e = p.db2; if (sDb2e.EndsWith(REPORT_FILE_EXT, StringComparison.CurrentCultureIgnoreCase)) { sDb2 = sDb2.Substring(0, sDb2.Length - REPORT_FILE_EXT.Length); } else { sDb2e += REPORT_FILE_EXT; } if (!string.IsNullOrEmpty(sDb2) && File.Exists(sDb2e)) { XmlDocument xDoc1 = new XmlDocument(); xDoc1.Load(sDb2e); long t1l = DateTime.Now.Ticks; if (xDoc == null) { if (File.Exists(sDbe)) { XmlDocument xDoc2 = new XmlDocument(); xDoc2.Load(sDbe); xDoc = DirectoryInfoDatabaseComparable.Compare(xDoc1, xDoc2, sDb + REPORT_FILE_SUFFIX); } } else { xDoc = di.Compare(xDoc1, sDb + REPORT_FILE_SUFFIX); } long t2l = DateTime.Now.Ticks; if (xDoc != null) { p.timeCompare = new TimeSpan(t2l - t1l); //bOpC = true; } } } } //p.form1.StopWorking(p.timeScan, p.timeCompare); }