下面是如何最大化console和改变其显示的字体颜色的代码,顺便包含了计时代码(帮助做性能分析):
class Program
{
[DllImport("kernel32.dll", ExactSpelling = true)]
private static extern IntPtr GetConsoleWindow();
private static IntPtr ThisConsole = GetConsoleWindow(); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); private const int HIDE = ;
private const int MAXIMIZE = ;
private const int MINIMIZE = ;
private const int RESTORE = ; private const int OldestPhaseNo = ; static void Main(string[] args)
{
// Set maximum console windows size
Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
ShowWindow(ThisConsole, MAXIMIZE); // Start the time watch
Stopwatch watch = new Stopwatch();
watch.Start(); // Stop the time wattch
Dictionary<string, string> ssqRecords = GetSsQiuRecords().Result;
watch.Stop(); // Change/Set the console's foregound clodr as green
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(watch.Elapsed.TotalSeconds); // Restart the time calculation to 0
watch.Restart();
SaveLotteryDataToLocalConfig(ssqRecords);
watch.Stop(); Console.WriteLine(watch.Elapsed.TotalSeconds);
// Revert back to the default color
Console.ForegroundColor = ConsoleColor.Gray; // Set the display buffer for console window
Console.SetBufferSize(, );
}
}