pat27

pat27

  • NA
  • 15
  • 0

Threads

Jul 30 2004 5:54 PM
hello, i have a question to the following code sample: using System; using System.Runtime.InteropServices; using System.Threading; class Test { static AutoResetEvent evt; static int count = 1; static void Main(string[] args) { if (args.Length > 0) { try { count = int.Parse(args[0]); } catch {} } evt = new AutoResetEvent(false); Timer t = new Timer(new TimerCallback(TimerCallback), null, 0, 5000); evt.WaitOne(); } static void TimerCallback(object state) { Console.WriteLine("Enumerating windows at {0:t}...", DateTime.Now); EnumWindows(new EnumWindowsProc(EnumWindowsCallback), IntPtr.Zero); if (--count == 0) evt.Set(); } static bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam) { if (hWnd != IntPtr.Zero) { string title = new string('\0', 260); int ret = GetWindowText(hWnd, title, 260); if (ret != 0) Console.WriteLine("0x{0:x8}: {1}", hWnd.ToInt64(), title.Substring(0, ret)); } return true; } [DllImport("user32.dll")] static extern bool EnumWindows(EnumWindowsProc proc, IntPtr lParam); delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); [DllImport("user32.dll", CharSet=CharSet.Auto)] static extern int GetWindowText(IntPtr hWnd, [Out] string title, int maxCount); } Whereat i can recognize that the Timer runs in an other thread than the main thread? I hope anybody can help me. Thanks in advance. yours sincerely, patrick

Answers (1)