no change
Main Topics
Browse All TopicsI'm firing off 4 asynch delegates, each with the same callback. Inside the callback I'm keeping track of a simple integer counter. When the counter reaches 4, it reaches up into the main GUI, and makes the appropriate panel visible, using Invoke. Everything works GREAT.
Now, if I lock windows, and then unlock it, my entire application is completely frozen - I can't click anything, and if I drag another window in front, then move it, the application will not re-paint, but instead becomes distorted.
This even happens if I go through the asynch routine, and then do some other stuff with the program, then lock windows.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
What AlexFM wrote is something you must do.
Invoke waits for the method to complete, so if an event is being handled by the user interface thread currently, Invoke will waitfor that handler to finish. Here is a potential for deadlock;
BeginInvoke is sometimes a better choice because it doesnt wait for the invoked method to finish runningit just adds the request to run the method to the frameworks internal event queue and then returns immediately.
Just an idea, that might help
It seems that when you lock windows the main thread or other threads "die" somehow!
If you can test the status of the treads, and discover if they are "alive" or "dead" it might give you and idea how to work it around.
Some more expirience expert can help more.
Remove Invoke/BeginInvoke call from asynchronous callback. Does the program freeze now?
Add a lot of Trace.WriteLine calls to all suspicious functions, specifically, all functions working with asynchronous delegate, Invoke/BeginInvoke call and UI callback function. It can look like this:
void DoSomething()
{
Trace.WriteLine("DoSomethi
Trace.WriteLine("Call BeginInvoke");
form.BeginInvoke(...);
Trace.WriteLine("BeginInvo
...
Trace.WriteLine("DoSomethi
}
...
Run DebugView and your program, reproduce the bug and see what call doesn't return in the DebugView. This should happen in some function running in the main application thread which is responsible for GUI update. Having this information, you can detect deadlock reason.
I completely got rid of the callback function - now I just have 4 delegate.begininvokes (and no form.Invoke or form.BeginInvoke). I put traces before and after each one.
Everything run 100% as expected, as it did before. The same problem stil exists though, which is that after locking windows, and unlocking it (logging back in), my application is now completely frozed, won't accept any input, can't re-paint, etc.
This is what the delegates getting called looks like, in case it will help at all.
lc = New LoadCustomerDelegate(Addre
Trace.WriteLine("start 1")
lc.BeginInvoke(oCust, Nothing, Nothing)
Trace.WriteLine("end 1")
lc = New LoadCustomerDelegate(Addre
Trace.WriteLine("start 2")
lc.BeginInvoke(oCust, Nothing, Nothing)
Trace.WriteLine("end 2")
lc = New LoadCustomerDelegate(Addre
Trace.WriteLine("start 3")
lc.BeginInvoke(oCust, Nothing, Nothing)
Trace.WriteLine("end 3")
lc = New LoadCustomerDelegate(Addre
Trace.WriteLine("start 4")
lc.BeginInvoke(oCust, Nothing, Nothing)
Trace.WriteLine("end 4")
The only thing which looks suspicious here is using BeginInvoke without EndInvoke, which causes small memory leak, however, this is obviously not enough.
Trying to recall some .NET internals that I know, I can say that using BeginInvoke without EndInvoke causes leaking IAsyncResult instance and one native Windows event. Possibly it is internally implemented using thread from the thread pool, which is released only when EndInvoke is called. I don't know whether this is enough to get this strange behavior.
Business Accounts
Answer for Membership
by: AlexFMPosted on 2007-09-14 at 08:50:19ID: 19892627
Try to replace Invoke with BeginInvoke for GUI update from the delegate callback.