Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

   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

Visit http://www.nico.gotdns.com

 

Now ONLINE!

  • Leaders
Posted

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

  • *Experts*
Posted
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.
Posted

 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

Visit http://www.nico.gotdns.com

 

Now ONLINE!

  • *Experts*
Posted

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.

Posted

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??

Visit http://www.nico.gotdns.com

 

Now ONLINE!

  • *Experts*
Posted

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.

Posted

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

Visit http://www.nico.gotdns.com

 

Now ONLINE!

Posted

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

Visit http://www.nico.gotdns.com

 

Now ONLINE!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...