static void Main(string[] args) { var custTimer = new TimeIt(); var executionTime = new TimeSpan(); //This overload lets you pass a params array executionTime = custTimer.Start(GenerateNumbers, 1, 2, 3, 4, 5); //Use an anonymous function executionTime = custTimer.Start(() => { //timer will stop at the end of this block of code }); //Wrap your code within an Using statement using (var byUsing = new TimeIt()) { GenerateNumbers(); //Before end using, retrieve elapsed time from object executionTime = byUsing.ElapsedTime; } //Use it with lambda expressions (lambda will return execution Time) by using Invoke Method() using (TimeIt.Invoke(ts => Console.Write("Method exec time: " + ts.Milliseconds))) GenerateNumbers(); //Pass to Invoke the function that will receive the TimeSpan before intern object disposal using (TimeIt.Invoke(ProcessResult)) GenerateNumbers(); //Keep the console open Console.ReadKey(); }
private void LoaderForm_Shown(object sender, System.EventArgs e) { lblProgressMessage.Text = string.Empty; Application.DoEvents(); // Make sure controls render before we do something. var cacheFiles = RootEntry.GetCacheFileList(_cdeList); var totalFiles = cacheFiles.Count(); var fileCounter = 0; barLoading.Step = totalFiles; barLoading.Maximum = totalFiles; // Not doing a background worker. _rootEntries = cacheFiles.Select(s => { _timeIt.Start(s); var re = RootEntry.LoadDirCache(s); _timeIt.Stop(); ++fileCounter; lblProgressMessage.Text = $"Loading catalog {fileCounter} of {totalFiles}"; barLoading.Value = fileCounter; Application.DoEvents(); // Get label to update. return(re); }).ToList(); Close(); }
public void LoadData(Func <int, bool> notifyCount) { var paths = new[] { _basePath }; var cacheFiles = RootEntry.GetCacheFileList(paths); var cacheFileCount = cacheFiles.Count; _loadMetric.Start("Loading catalogs"); _notifyCount(cacheFileCount); _rootEntries = cacheFiles.Select(s => { var re = RootEntry.LoadDirCache(s); --cacheFileCount; _notifyCount(cacheFileCount); return(re); }).ToList(); _loadMetric.Stop(); }