shahprabal
asked on
Threading best practices and some moderately complex examples
I am interested in using threads and want some best practices example. I know how to start and run a simple sub but I saw some examples where delegates were used and would like to know about some more than simple applications of threading. If you have used threads in situations where it worked out great would like to know about it (i know about the basic scenarios like keeping the UI responsive, but would like some feedback from someone who has used it for something more uncommon like using beginexecutereader to get datareader in a different thread, or to populate some control periodically, etc).
Thanks.
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Idle_Mind ... this was exactly what I wanted... pointers and dos dont from someone who has used threads in apps... is there anything that you are unfamiliar with ????????
"is there anything that you are unfamiliar with ????????"
LOL...trust me...there is PLENTY in the programing world, even in VB.Net, that I have ABSOLUTELY no clue how to do! =)
LOL...trust me...there is PLENTY in the programing world, even in VB.Net, that I have ABSOLUTELY no clue how to do! =)
ASKER
I doubt that.... Still thanks for making us feel like n00bs :)
ASKER
Idle Mind, I am working on a multithreaded app and am populating a treeview control with the servers on the network in a seperate thread... even though the form loads while the control is being populated the ui is not responsive... to fix this I added Application.DoEvents in the loop that populates the control and the app behaves much better... according to ur list above calling Application.DoEvents is a no-no... can you elaborate on that...
You're calling DoEvents() from within the Thread? Or after you have used Delegates/Invoke to get back on the main UI thread?
The problems I've seen with DoEvents() from a different Thread were when it was being callled repeatedly in quick succession from a Timer or infinite loop in another thread.
The problems I've seen with DoEvents() from a different Thread were when it was being callled repeatedly in quick succession from a Timer or infinite loop in another thread.
ASKER
Basically this is what I am trying to do :
https://www.experts-exchange.com/questions/22494712/Threading-Using-Invoke-and-Begin-Invoke.html
And I got the program to work both ways... i.e. using a background worker and without it...
First I tried without it... works as expected... but the UI is not responsive... when I put the DoEvents in the loop that populates the TreeView... the form UI responds better (not as good as I would have liked)...
So I looked at the background worker and implemented that solution thinking I can trigger the ProgressChanged event and have DoEvents inside the event... Also I thought since BackgroundWorker is a built in component it might work better with the UI... but triggering DoEvents through the event is not giving me the desired result...
Also I tracked the CPU usage in both senarios... not even hitting 10%.... using Pentium D 3.00Ghz dual core cpu... any thoughts
https://www.experts-exchange.com/questions/22494712/Threading-Using-Invoke-and-Begin-Invoke.html
And I got the program to work both ways... i.e. using a background worker and without it...
First I tried without it... works as expected... but the UI is not responsive... when I put the DoEvents in the loop that populates the TreeView... the form UI responds better (not as good as I would have liked)...
So I looked at the background worker and implemented that solution thinking I can trigger the ProgressChanged event and have DoEvents inside the event... Also I thought since BackgroundWorker is a built in component it might work better with the UI... but triggering DoEvents through the event is not giving me the desired result...
Also I tracked the CPU usage in both senarios... not even hitting 10%.... using Pentium D 3.00Ghz dual core cpu... any thoughts
ASKER