public void TestSleep(int waitTimeSeconds) { var startTime = DateTime.UtcNow; Console.WriteLine("Sleeping for {0} seconds", waitTimeSeconds); ConsoleMsgUtils.SleepSeconds(waitTimeSeconds); var elapsedSeconds = DateTime.UtcNow.Subtract(startTime).TotalSeconds; Console.WriteLine("Done after {0:F3} seconds", elapsedSeconds); Assert.AreEqual(0, Math.Abs(elapsedSeconds - waitTimeSeconds), 0.1, "Did not sleep as long as expected"); }
private static void ShowProgramHelp() { var exeName = Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location); try { Console.WriteLine(); Console.WriteLine(ConsoleMsgUtils.WrapParagraph( "This program estimates the value of Pi, using either a single thread or multiple threads. " + "This can be used to simulate varying levels of load on a computer")); Console.WriteLine(); Console.WriteLine("Program syntax:" + Environment.NewLine + exeName); Console.WriteLine(" [/Mode:{1,2,3,4}] [/RunTime:Seconds] [/Threads:ThreadCount] [/UseTiered] [/Preview]"); Console.WriteLine(); Console.WriteLine("/Mode:1 is serial calculation (single thread)"); Console.WriteLine("/Mode:2 uses a Parallel.For loop"); Console.WriteLine("/Mode:3 uses the Task Parallel Library (TPL) framework, initializing with factories"); Console.WriteLine("/Mode:4 uses the Task Parallel Library (TPL) framework, but without factories"); Console.WriteLine(); Console.WriteLine("Specify the runtime, in seconds, using /RunTime"); Console.WriteLine(); Console.WriteLine("Specify the number of threads to use with /Threads"); Console.WriteLine("If not specified, all cores will be used; " + GetCoreCount() + " on this computer"); Console.WriteLine(); Console.WriteLine(ConsoleMsgUtils.WrapParagraph( "Use /UseTiered with modes 2 through 4 to indicate that different threads should run for tiered runtimes " + "(each thread will run for a shorter time than the previous thread)")); Console.WriteLine(); Console.WriteLine("Use /Preview to preview the threads that would be started"); Console.WriteLine(); Console.WriteLine("Program written by Matthew Monroe for the Department of Energy (PNNL, Richland, WA) in 2015"); Console.WriteLine("Version: " + GetAppVersion()); Console.WriteLine(); Console.WriteLine("E-mail: [email protected] or [email protected]"); Console.WriteLine("Website: https://omics.pnl.gov or https://panomics.pnnl.gov/"); Console.WriteLine(); // Delay for 1 second in case the user double clicked this file from within Windows Explorer (or started the program via a shortcut) ConsoleMsgUtils.SleepSeconds(1); } catch (Exception ex) { ShowErrorMessage("Error displaying the program syntax", ex); } }