private void DisplayTimerCaps() { var caps = WinApiCalls.QueryTimerResolution(); CurrentLabel.Text = "Current: " + (caps.PeriodCurrent / 10000.0) + " ms"; MinLabel.Text = "Max: " + (caps.PeriodMin / 10000.0) + " ms"; MaxLabel.Text = "Min: " + (caps.PeriodMax / 10000.0) + " ms"; }
private static void Main(string[] args) { bool useWindow = true; bool takeNext = false; uint timeoutFromConsole = 0; foreach (string arg in args) { if (arg == "-c") { useWindow = false; } else if (arg == "-t") { takeNext = true; } else if (takeNext) { takeNext = false; double val; if (double.TryParse(arg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out val)) { timeoutFromConsole = (uint)(val * 10000); } } } if (useWindow) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(args)); } else { if (timeoutFromConsole == 0) { Console.WriteLine("resetting timer"); WinApiCalls.SetTimerResolution(0, false); } else { Console.WriteLine("setting timer to {0}", timeoutFromConsole); WinApiCalls.SetTimerResolution(timeoutFromConsole); } while (true) { System.Threading.Thread.Sleep(100); } } }
public MainForm(string[] args) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); ResourceManager resources = new ResourceManager(typeof(MainForm)); this.Resize += MainForm_Resize; notifyIcon1.BalloonTipText = "TimerTool running..."; notifyIcon1.BalloonTipTitle = "TimerTool"; notifyIcon1.BalloonTipIcon = ToolTipIcon.Info; notifyIcon1.Text = "TimerTool"; notifyIcon1.Icon = (Icon)resources.GetObject("TimerIcon"); notifyIcon1.Click += NotifyIcon1_Click; //apply commandline args allowVisible = true; var i = 0; foreach (var arg in args) { if (arg == "-t") { if (args.Length > (i + 1)) { double val; if (double.TryParse(args[i + 1], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out val)) { WinApiCalls.SetTimerResolution((uint)(val * 10000)); } } } if (arg == "-minimized") { allowVisible = false; } i++; } }
void UnsetTimerClick(object sender, EventArgs e) { WinApiCalls.SetTimerResolution(0, false); }
void SetTimerButtonClick(object sender, EventArgs e) { WinApiCalls.SetTimerResolution((uint)(numericUpDown2.Value * 10000)); }