Click here to Skip to main content
15,915,742 members
Home / Discussions / C#
   

C#

 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 6:46
pat27088129-Jul-04 6:46 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 6:49
protectorHeath Stewart29-Jul-04 6:49 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 7:45
pat27088129-Jul-04 7:45 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 9:09
protectorHeath Stewart29-Jul-04 9:09 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 10:27
pat27088129-Jul-04 10:27 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 10:48
protectorHeath Stewart29-Jul-04 10:48 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 0:39
pat27088130-Jul-04 0:39 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 3:43
protectorHeath Stewart30-Jul-04 3:43 
pat270881 wrote:
either i'm too stupid to solve this problem or i don't know

This is why you read, or forever be a newbie.

You're doing several things wrong, here. First, you can't declare a variable inside one scope (i.e., method) and access it from another (like your AutoResetEvent). You have to declare this as a field, but you can instantiate and assign an instance to that field in another method.

Second, you're instantiating your callback outside of a method. This is not supported by C# or even the CLI (the specs on which .NET is built).

To top it all off, do you even know what the AutoResetEvent is and why you're using it? You should've read about that, too. It's all in the .NET Framework SDK which should be installed locally if you took the default installation options for VS.NET, and is always available online at http://msdn.microsoft.com/library[^].

The examples you see require some understanding. They are seldom complete. Be sure to read about the Timer class and don't just rely on the examples, or you'll never learn anything.

If you were to put that original code I gave you for enumerating windows into a method, the following is roughly what you should use:
using System;
using System.Threading;
// using...

class Example
{
  bool stop = false;
  AutoResetEvent waitHandle;
  static void Main()
  {
    waitHandle = new AutoResetEvent(false);
    Timer t = new Timer(new TimerCallback(EnumerateWindows), null, 5000,
      Timeout.Infinite);
    waitHandle.WaitOne(); // Wait indefinitely until signalled.
  }
  static void EnumerateWindows(object state)
  {
    if (stop) waitHandle.Set(); // Signal the wait handle.
    else
    {
      // Enumerate your windows as I showed you before here.
    }
  }
  // Declare window enumeration methods and callbacks as I showed you
  // before here.
}
You should definitely read about any class, property, method, etc. that you don't understand first before asking questions. The class library documentation should always be the first place you check.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 4:58
pat27088130-Jul-04 4:58 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 5:33
protectorHeath Stewart30-Jul-04 5:33 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 6:21
pat27088130-Jul-04 6:21 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 7:30
protectorHeath Stewart30-Jul-04 7:30 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 7:47
pat27088130-Jul-04 7:47 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 8:04
protectorHeath Stewart30-Jul-04 8:04 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 9:17
pat27088130-Jul-04 9:17 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart30-Jul-04 9:29
protectorHeath Stewart30-Jul-04 9:29 
GeneralRe: logg/scan open windows - important question! Pin
pat27088130-Jul-04 9:52
pat27088130-Jul-04 9:52 
GeneralRe: logg/scan open windows - important question! Pin
pat2708812-Aug-04 4:28
pat2708812-Aug-04 4:28 
GeneralError while deploying with the emulator Pin
mathon16-Aug-04 7:53
mathon16-Aug-04 7:53 
GeneralRe: logg/scan open windows - important question! Pin
pat27088129-Jul-04 5:43
pat27088129-Jul-04 5:43 
GeneralRe: logg/scan open windows - important question! Pin
Heath Stewart29-Jul-04 6:21
protectorHeath Stewart29-Jul-04 6:21 
GeneralA Comprehensive Logging Package for .NET Pin
pat27088128-Jul-04 5:40
pat27088128-Jul-04 5:40 
GeneralRe: A Comprehensive Logging Package for .NET Pin
Heath Stewart28-Jul-04 6:39
protectorHeath Stewart28-Jul-04 6:39 
GeneralRe: A Comprehensive Logging Package for .NET Pin
pat27088128-Jul-04 6:53
pat27088128-Jul-04 6:53 
GeneralRe: A Comprehensive Logging Package for .NET Pin
Heath Stewart28-Jul-04 6:59
protectorHeath Stewart28-Jul-04 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.