NicoVB Posted July 16, 2003 Posted July 16, 2003 Private Sub Dossier_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Load1() Load2() 'etc End Sub How do you use 'Application.DoEvents()' in this statement to get the BEST performance. 1. Do you place it in the seperate methods ??? 2. Do you place the statement just here in this Load Event, one time or several times between each call????? Thanks Nico Quote Visit http://www.nico.gotdns.com Now ONLINE!
Leaders dynamic_sysop Posted July 16, 2003 Leaders Posted July 16, 2003 if you want to ensure that Load1 gets loaded before Load2 you can do this : Private Sub Dossier_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Load1() Application.DoEvents() Load2() Application.DoEvents() End Sub if you only want to ensure that before leaving the Dossier_Load sub , it's loaded both , you could do this : Private Sub Dossier_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Load1() Load2() Application.DoEvents() End Sub Quote
*Experts* Volte Posted July 16, 2003 *Experts* Posted July 16, 2003 You don't need DoEvents in this case. At the point of their execution, the machine is already free to do anything it might need to do. You may want to look into threading to do this though, as it will cause these commands to run separately from the rest of your program, so it may be faster. Quote
NicoVB Posted July 16, 2003 Author Posted July 16, 2003 Is there any problem if that new thread works on the same form, because i got an error when I tested that. Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Experts* mutant Posted July 16, 2003 *Experts* Posted July 16, 2003 Can you show sopme of your code and tell what the error was? It will be easier to figure out that way. :) Quote
NicoVB Posted July 16, 2003 Author Posted July 16, 2003 I will tomorrow attach some code, but I can say it works with a DataReader who reads from the database and gives the form the information. Quote Visit http://www.nico.gotdns.com Now ONLINE!
begin_with_A Posted July 17, 2003 Posted July 17, 2003 (edited) What is the code context? Can u elaborate more by typing some code in here? -A Edited July 17, 2003 by Squirm Quote
NicoVB Posted July 17, 2003 Author Posted July 17, 2003 Dossier_Load 'Location changes of few controls 'Data binding with some textboxes 'Filling another Tab with some info from a database That's it. But can't give you the code right now. Can someone explain me how to 'thread' this??? (I have one Form with a tabcontrol with several Tabs. I want to load in the background the other tabs that are not seen by the user until they click on that tab) Thanks Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Experts* mutant Posted July 17, 2003 *Experts* Posted July 17, 2003 Since I dont know what excatly you have there I cant be sure this will not generate errors. You can do something like this: Dim thread1 As New Threading.Thread(AddressOf ControlMovingSub) thread1.Start() Dim thread2 As New Threading.Thread(AddressOf DataBindingSub) thread2.Start() Dim thread3 As New Threading.Thread(AddressOf TabFillingSub) thread3.Start() This could generate errors, because as I said before some things cant be shared between threads, like you couldnt create a control in your own thread and add it to the form's control collection becuase its another thread. Quote
NicoVB Posted July 17, 2003 Author Posted July 17, 2003 Well, Thanks for that information. Indeed, I have a TabFillingSub with some controls that I create and then try to add them to a Tab. But this doesn't work like you said because of the threads. Do you know another solution for that?? Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Experts* mutant Posted July 17, 2003 *Experts* Posted July 17, 2003 I assume that when you move your controls you dont create any in that sub, and the same with the databinding sub, although you can access the controls from the thread you create its still not the best method becuase the controls are not thread safe so they dont work very well if modified from another threads, but this method could still work. If the only thing your sub does is move the controls then I dont think you need you need another thread for it, because to be totally safe with accessing controls from another thread you would need the form's thread anyway. But again, you can access them just directly from that thread and it should work but its not guaranteed to work. As for your tabs, I dont think you have much choice than just filling them from your form's thread. Quote
NicoVB Posted July 18, 2003 Author Posted July 18, 2003 Thanks for the information. Now I'm trying to use at least those two first threads. But I have a problem with the second. I have Dim thread2 As New Threading.Thread(AddressOf FillContactGrid(TabContacts)) thread2.Start() But that's wrong, because you aren't allowed to use parentheses. But what do I have to do then, because I need to give a variable to the method!!!! Nico Quote Visit http://www.nico.gotdns.com Now ONLINE!
NicoVB Posted July 18, 2003 Author Posted July 18, 2003 I have allready solved the problem by creating another sub (without parameters) in which I call the method I want. 1.Is this the right way to do that???? Now this problem occured during threading: --------------------------------------------------------- CType(pnl.Control, ContactenTab).GridEx2.SetDataBinding(objDSContact, "KON") An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll Additional information: Besturingselementen die zijn gemaakt voor de ene thread kunnen niet het bovenliggende item zijn van een besturingselement op een andere thread.(Translation: Controls that are created for one thread can't be the item of a control of another thread) 2.What to do??? Nico Quote Visit http://www.nico.gotdns.com Now ONLINE!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.