Click here to Skip to main content
15,884,893 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Afternoon All,

I am using a left hand ribbon control i made to load up MDI Child Forms, the problem i have is that some of them have a significant amount of controls on them so takes a few seconds upon activation to relase the thread.

My concern here is that if i multiple click the ribbon button it results in a HRESULT E_FAIL -2147467259 error code being returned which is fine but then becuase the form is being loaded,unloaded and reloaded multiple times causing the application to hang.

When the user clicks the button i have the button disable while it processing and the re-enable again after it is finished, my question is here. how do i get the program to stop queueing click events whilst the thread is busy

so we know we cant click on things when disabled but becuase the event is being queued up and when the thread is released it then processes the next fired event - i want to completely prevent further clicks in this area until the thread is released.

Any thoughts?
Regards
Dev
Posted

1 solution

You could call the Application.DoEvents[^] method immediately prior to re-enabling the control. It should consume the waiting messages - i.e. they will fire but be ignored because the control is disabled. Please take note of the warnings and suggestions on that link.

You could also consider doing the process on another thread - Sacha Barber has written a series of articles here on CodeProject that might help - this link is for the first Beginners Guide to Threading in .NET: Part 1 of n[^]
 
Share this answer
 
Comments
Dev O'Connor 30-Dec-14 4:13am    
Doh!! sometimes the simplest things. Most of the forms only have a couple of controls however just a couple have quite a few, i dont want to implement threading for a small minority and it is simply for a second or 2 but the form moves whilst its loading so users can see its loading but i know when its deployed the users wont be as careful as they should be rapidly clicking etc which of course causes the error mentioned above...

Thanks for the reminder of DoEvents, i know DoEvents is a kinda dirty way to do it but for simplicity ill use it as i dont want to have to deploy a threading model within my application for just a small minority of forms.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900