tags:

views:

1190

answers:

5
+3  A: 

Not sure why. But are you sure the running application is compiled using the code you are stepping through. I have seen this sort of thing when the code is different to what is actually being executed.

David McEwing
+1  A: 

Is your program multi threaded?

I have seen situations where I check a value and then try using it only to find its changed. Whats happened is that another thread as changed the value after I checked it but before I used it.

trampster
+1  A: 

Are you certain that you're actually on the line you have highlighted? You can click around in the call stack window and make any part of the call stack the "current" line in the sense that you can get the value of variables there and so forth.

The point being, perhaps EndedUsingApplication sets ActiveApplication to null, so that ActiveApplication wasn't null when it evaluated the if, but now it's null when you're evaluating it in the debugger.

Have you put a breakpoint on the EndedUsingApplication(ActiveApplication) line to make sure ActiveApplication is null before you execute that line?

Kyralessa
+50  A: 

Have you overloaded != ?

Jay Riggs
See the original question for explanation.
Nippysaurus
Wow, great call.
Noon Silk
i think there's a lesson to be learned here
rik.the.vik
yes, the lesson is if anyone tries to overload an operator, you hit them with a fish.
Noon Silk
Shall we truck in some nice, aged trout from IRC land?
jrista
+1  A: 

I think a better approach is to use Object.ReferenceEquals as it is more explicit:

public static bool operator ==(ActiveApplication a, ActiveApplication b)
     {
     // same reference so equals is true - will be true for null == null
     if (object.ReferenceEquals(a, b))
        return true;

     // one is null and the other is not
     if (object.ReferenceEquals(a, null) || object.ReferenceEquals(b, null))
        return false;

     // dealt with all combinations of null - compare fields
     return a.process_name == b.process_name && a.window_title == b.window_title;
     }

  public static bool operator !=(ActiveApplication a, ActiveApplication b)
     {
     return !(a == b);
     }
dkackman