Multi-Threading

sevensilly

Member
Joined
May 8, 2007
Messages
10
Programming Experience
1-3
Hi All,

I have an application that performs specific SMS, LDAP, and SQL/ADO actions within the same subroutine. The routine is executed after an event (button click).

I've written the app as such that this routine is executed as a new thread. Before starting said thread, I have another thread that calls a subroutine that instantiates a class I wrote, which is essentially a form with a progress bar inside of it. The trouble is when I start this thread, the form is not visible. Is this a property of the thread object that I need to set or am I simply mis-using threading?
 
Typically when doing VB.net id use the main application thread as the UI thread. This means you instantiate your form when the app runs (as with a non-multi-threaded app), and then I would create new threads from there to do your background processing.

So have a button your main form which fires off the threads to perform your SMS, LDAP etc.. queries.

I'd probably need to see some code to be more helpful - but I think this approach makes sense in terms of application architecture.

mafro
 
Thanks for the suggestion- I'll have some code to re-write and some new subroutines.

I guess I'm still trying to figure out why the form wouldn't be visible if started as thread. Here's a snippet of my code:

Sub Click_Button.. Handles Button.Click
Dim thShowProgressBarForm as Thread(AddressOf showProgBar)
thShowProgressBarForm.Start()
.... etc. rest omitted
End Sub

Sub showProgBar()
Dim obProgBarForm as New ProgBarForm
obProgBarForm.Show
End Sub

ProgBarForm is a class I wrote which is just a form with a progressbar inside of it.
 
Show the progress form from UI thread instead.
 
Thanks for the responses. I've re-written it as such that the showProgBar is called from the from thread and it works wonderfully.

JohnH - I receive an email notification that indicated you had replied. Did you edit your original response? This is what I got:

*** The showProgBar thread is finished after form.Show method is called, so all its objects are destroyed. Show it from UI thread. ***

This statement has me confused. Wouldn't the thread thShowProgressBarForm only finish after it is finished executing the code within the routine it is bound to?
 
Yes, that is confusing, isn't it? The email notification is amazingly fast sometimes. It would appear so, but I discovered the other thread didn't finish while the form disappeared when I stopped the application by closing UI form and it didn't stop after all. I'm not exactly sure why either occurs, why the form/thread remains when the code is finished (which it is because Show method isn't a blocking call, the thread is finished and there is technically no references keeping any objects there alive), and why the form in that case gets hidden when the thread don't stop as would be natural it would. It could be something with the application message loop, I also had the application framework enabled and "when last form closes" option on, so I think this is related. I also now tried this with .Net 1 where this doesn't not appear to happen, the thread is finished immediately and as expected does not "hang" the application on exit, here the application framework is also not present, so that seems to confirm it. In both cases the thread reports IsAlive=False.

You mean you notify the progress form on UI thread from working thread, right?
 
Back
Top