Search code examples
c#.netmultithreadinginvokerequired

What happen with my InvokedRequired?


What wrong with my code ??

Why it not go to true statement ?

enter image description here


Solution

  • Your if statement has three conditions - you're only showing two of them in the debugger.

    I suspect that explains why you're seeing something odd - but I don't think your code is appropriate to start with. For one thing, you're testing the same condition twice, which is pointless (did you mean one of them to be lockScreen rather than loginScreen?) - but more importantly, if one of those InvokeRequired properties returns false, you won't be using BeginInvoke for any of the forms... even if InvokeRequired returned true for that form.

    I suggest you split this up into three separate blocks, each of which checks and acts on a single form.