Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Threading and VM
Message
From
28/07/2011 01:59:23
 
 
To
27/07/2011 14:34:55
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Database:
Oracle
Application:
Desktop
Miscellaneous
Thread ID:
01519054
Message ID:
01519425
Views:
22
>>>>
>>>>Wasn't my code :-}
>>>>TBH I didn't weigh up the pros and cons but it looked as if either could work.....
>>>
>>>
>>>Yep, it was mine. I know there is some room here to do this a bit different and the next time out it will get revisited. However now it works perfect and for some reason only needed to be slowed down. This is the part that is a bit puzzling. Apparently in VS with the debugger attached it runs just slow enough to be fine, but outside running the exe it gets missed. It isn't the value that is changing and causing the problem. The value changes to "LoginReady" and is logged; never changes, but the while loop never breaks out.. slowing it down a half second fixes it. I don't understand why really.
>>
>>Still sounds a bit risky to me - and a AutoResetEvent is simple to implement. e.g: Main Thread:
private static AutoResetEvent StartupStatusChanged = new AutoResetEvent(false);
>>//Then when you want to notify the thread to carry on:
>>StartupStatusChanged.Set();
Then your DoWork could be something like:
            StartupStatusChanged.WaitOne();
>>            switch (StartupWorkerStatus)
>>            {
>>                case BackgroundWorkerStatus.LoginReady:
>>                    {
>>                        //Elided
>>                        break;
>>                    }
>>                case BackgroundWorkerStatus.Failed:
>>                    {
>>                        break;
>>                    }
>>                    //etc
>>            }
>
>
>Here is a question. If I use the AutoResetEvent object and have a autoResetEvent.WaitOne(); in my thread, it appears I cannot issue a authenticationWorker.CancelAsync(); I just tested this and it appears to still wait for the Set(); I may have to check for a cancel right after the WaitOne();

You can issue a CancelAsync() but the background thread is not going to receive it until the WaitOne() clears - so, yes, add a check immediately after that.
Alternatively, since you have a BackgroundWorkerStatus.Cancelled enum you could just set StartupWorkerStatus to that and handle the cancellation in the switch ?
Previous
Reply
Map
View

Click here to load this message in the networking platform