Access mainform while subform is updating
-
I setup a form (subform) inside another form (mainform)at runtime. While some methods are being executed, the data in this subform also gets updated. However, I can not do anything else in the mainform. I have also tried setting the subform up as a control but I have the same problem. Is there a way I can access the mainform while the subform is updating. Any help will be greatly appreciated, Thanks in advance, Michael
-
I setup a form (subform) inside another form (mainform)at runtime. While some methods are being executed, the data in this subform also gets updated. However, I can not do anything else in the mainform. I have also tried setting the subform up as a control but I have the same problem. Is there a way I can access the mainform while the subform is updating. Any help will be greatly appreciated, Thanks in advance, Michael
I presume the process going on in the subform is reading from the database or some other long running process. This long running process needs to be separated onto another thread (backgroundworker thread is a good place to start.) This allow the UI on the main thread to respond.
Never underestimate the power of human stupidity RAH
-
I setup a form (subform) inside another form (mainform)at runtime. While some methods are being executed, the data in this subform also gets updated. However, I can not do anything else in the mainform. I have also tried setting the subform up as a control but I have the same problem. Is there a way I can access the mainform while the subform is updating. Any help will be greatly appreciated, Thanks in advance, Michael
To add to Mycroft's answer, all long running operations should be done on a separate thread to the UI. The problem with that is you cannot update the UI from a different thread. The BackgroundWorker[^] component is a perfect fit for this situation as it's
ProgressChanged
andRunWorkerCompleted
events will be raised on your UI thread so that problem is solved, and theDoWork
event is raised on the worker thread so you don't have to get involved any more than that. If you need to pass data around then the various methods/event arguments have an object you can use, alternatively I made a generic version which you can find here[^].Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)