Exemple #1
0
        private void addHashesWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            ShowWorkingAnimation();

            TimeSpan readFileTimeTotal  = TimeSpan.Zero;
            TimeSpan filterAddTimeTotal = TimeSpan.Zero;

            TimeSpan totalRuntimeTotal = TimeSpan.Zero;
            TimeSpan averageAddTime    = TimeSpan.Zero;

            Stopwatch readFileTimer     = Stopwatch.StartNew();
            Stopwatch filterAddTimer    = Stopwatch.StartNew();
            Stopwatch totalRuntimeTimer = Stopwatch.StartNew();

            int counter = 0;

            readFileTimer.Restart();
            string[] lines = File.ReadAllLines((string)e.Argument);
            readFileTimeTotal = readFileTimer.Elapsed;
            totalRuntimeTimer.Restart();
            foreach (string line in lines)
            {
                if (addHashesWorker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                filterAddTimer.Restart();
                filter.AddElement(line);
                filterAddTimeTotal = filterAddTimeTotal.Add(filterAddTimer.Elapsed);

                /*
                 * if (counter % 1000 == 0)
                 * {
                 *      refreshControlsTimer.Restart();
                 *      RefreshControls();
                 *      refreshControlsTimeTotal = refreshControlsTimeTotal.Add(refreshControlsTimer.Elapsed);
                 * }
                 */

                counter++;
            }
            totalRuntimeTotal = totalRuntimeTimer.Elapsed;

            long ticks = filterAddTimeTotal.Ticks / counter;

            averageAddTime = new TimeSpan(ticks);

            string timersReport =
                $"Total runtime: {FormHelper.FormatTimeSpan(totalRuntimeTotal)} (File read: {FormHelper.FormatTimeSpan(readFileTimeTotal)}, Add elmnts: {FormHelper.FormatTimeSpan(filterAddTimeTotal)} ttl., {FormHelper.FormatTimeSpan(averageAddTime)} avg.)";

            e.Result = timersReport;
        }