VB.NET Threading Questions - Worker Thread Hanging the UI!
Posted on 2008-10-30
I use threading all through a large application and have encountered a problem that i can't work out!
I am writing a single 'server' application to do a number of jobs for the company, this will involve mainly syncing up the website and doing some database work every few seconds. One of the other applications is checking SMS messages on a connected Nokia phone and handle them (i.e. send them off in an e-mail, write replies etc)
The issue is that every time i check the phone, the application hangs ... the obvious solution was to put the method into a thread that i simply fire off every 20 seconds.
Now that i have moved the method into a thread using the following:
Dim oThread As New Threading.Thread(AddressOf RefreshNokiaInbox)
oThread.Priority = Threading.ThreadPriority.Lowest
Private Sub RefreshNokiaInbox()
Dim oColl As HTFR.Objects.NokiaSMS.NokiaInternalStructures.NokiaObj_SMSItemCollection = HTFR.Objects.NokiaSMS.NokiaInternalStructures.NokiaObj_SMSItemCollection.GetBlankCollection
'Tell the UI Thread that we are refreshing the Inbox
Dim oDel As New del_SubCallbackNoArgs(AddressOf RefreshNokiaInbox_Callback_Started)
'returns a collection of business objects containing the sms message details on the phone
oColl = m_oNokiaPhoneItem.Inbox
Catch ex As Exception
'Tell the UI thread that we have completed
Dim oDelComp As New del_RefreshInboxCallback(AddressOf RefreshNokiaInbox_Callback_Comp)
Now, the issie is, that when this method is run ... the main UI still hangs!
My understanding is that if i put something in a thread, it doesn't touch the main UI until i make a callback with a delegate, so how can a worker thread lock up the main UI (but not the whole computer?)
The one thing i didn't want to do was write a different application for each job that i need to perform, surely firing off a thread for each 'job' is the same as having them running as different applications or does the OS handle the seperate programs better?