By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

Basic multithreading problem

P: n/a
Hi guys, thanks in advance.

trying to implement some multithreading here :
VS 2003
VB.net winforms
I have a dropdown on a form which has list of vendors, when the user selects
a vendor from this dropdown, a new thread is created which calls a webservice
and the webservice returns the list of cities the vendor is in and this data
is set as the datasource of the city dropdown on the same screen. The thread
takes 4-5 seconds to do all this and all this Works like a charm, by the time
the user some to the city dropdown , it already has the list of cities the
user has selected .

Now what i want to do is when the user selects mutiple values from the
Source dropdown and if there is already a thread created from the user
selection of the previous value (I.e within this 4-5 sec time preriod), i
want to suspend the old thread and then start a new thread which gets the
cities for the new vendor the user has selected and below is the code that i
have. But the problem is when user selects multiple values from the vendor
dropdown in the 4-5 second time period, the thread takes forever, what is
happening here, is it that all the thread that were started at queyed even if
i am suspending it or what how can i stop this from happening, i.e when the
user selects a vendor then i want to suspend any previous thread which was
getting the list of cities for the previous vendor and get the thread started
with the new vaendor selection. Could the problem be due to the webserivce
that the thread creates? please suggest
Waiting for a suggestion.
Below is the code that i am running.

Creating the thread when the user selects a new vendor from the dropdown :

Private function Vendorchanged()
Try
'Checking to suspend any old thread which might still be acttive from
previous selection
If Not thread_refreshcontact Is Nothing AndAlso
thread_refreshcontact.IsAlive = True Then

thread_refreshcontact.Suspend()

End If

'Beging to re-initialized the thread
thread_refreshcontact = Nothing
thread_refreshcontact = New
Threading.Thread(AddressOf RefreshCity)
thread_refreshcontact.Name = "vendorcity"
thread_refreshcontact.IsBackground = True

thread_refreshcontact.Start()
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End function
'Function being called by the thread above
Private Sub RefreshCity()

Dim custid As Int32 = 0
Dim Dr As DataRow
Dim vendorid As Int32 = 0

Try

DtCity = <CAll the webserivce which returns the datatable with the cities>
Catch ex As Exception

MsgBox(ex.ToString)
End Try

End Sub

Sameer
Aug 18 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Are you sure you want to get the cities on a different thread..it seems that
that is the critical path execution and you would want to wait until you have
the cities listed in the listbox anyway?
--
Dennis in Houston
"sameer" wrote:
Hi guys, thanks in advance.

trying to implement some multithreading here :
VS 2003
VB.net winforms
I have a dropdown on a form which has list of vendors, when the user selects
a vendor from this dropdown, a new thread is created which calls a webservice
and the webservice returns the list of cities the vendor is in and this data
is set as the datasource of the city dropdown on the same screen. The thread
takes 4-5 seconds to do all this and all this Works like a charm, by the time
the user some to the city dropdown , it already has the list of cities the
user has selected .

Now what i want to do is when the user selects mutiple values from the
Source dropdown and if there is already a thread created from the user
selection of the previous value (I.e within this 4-5 sec time preriod), i
want to suspend the old thread and then start a new thread which gets the
cities for the new vendor the user has selected and below is the code that i
have. But the problem is when user selects multiple values from the vendor
dropdown in the 4-5 second time period, the thread takes forever, what is
happening here, is it that all the thread that were started at queyed even if
i am suspending it or what how can i stop this from happening, i.e when the
user selects a vendor then i want to suspend any previous thread which was
getting the list of cities for the previous vendor and get the thread started
with the new vaendor selection. Could the problem be due to the webserivce
that the thread creates? please suggest
Waiting for a suggestion.
Below is the code that i am running.

Creating the thread when the user selects a new vendor from the dropdown :

Private function Vendorchanged()
Try
'Checking to suspend any old thread which might still be acttive from
previous selection
If Not thread_refreshcontact Is Nothing AndAlso
thread_refreshcontact.IsAlive = True Then

thread_refreshcontact.Suspend()

End If

'Beging to re-initialized the thread
thread_refreshcontact = Nothing
thread_refreshcontact = New
Threading.Thread(AddressOf RefreshCity)
thread_refreshcontact.Name = "vendorcity"
thread_refreshcontact.IsBackground = True

thread_refreshcontact.Start()
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End function
'Function being called by the thread above
Private Sub RefreshCity()

Dim custid As Int32 = 0
Dim Dr As DataRow
Dim vendorid As Int32 = 0

Try

DtCity = <CAll the webserivce which returns the datatable with the cities>
Catch ex As Exception

MsgBox(ex.ToString)
End Try

End Sub

Sameer
Aug 18 '06 #2

P: n/a
Dennis, thanks for your answer, actually this scenario was the closest to
what i am trying to achive here so i am pretty sure that i want to get the
cities on a different thread.

thanks

"Dennis" wrote:
Are you sure you want to get the cities on a different thread..it seems that
that is the critical path execution and you would want to wait until you have
the cities listed in the listbox anyway?
--
Dennis in Houston
"sameer" wrote:
Hi guys, thanks in advance.

trying to implement some multithreading here :
VS 2003
VB.net winforms
I have a dropdown on a form which has list of vendors, when the user selects
a vendor from this dropdown, a new thread is created which calls a webservice
and the webservice returns the list of cities the vendor is in and this data
is set as the datasource of the city dropdown on the same screen. The thread
takes 4-5 seconds to do all this and all this Works like a charm, by the time
the user some to the city dropdown , it already has the list of cities the
user has selected .

Now what i want to do is when the user selects mutiple values from the
Source dropdown and if there is already a thread created from the user
selection of the previous value (I.e within this 4-5 sec time preriod), i
want to suspend the old thread and then start a new thread which gets the
cities for the new vendor the user has selected and below is the code that i
have. But the problem is when user selects multiple values from the vendor
dropdown in the 4-5 second time period, the thread takes forever, what is
happening here, is it that all the thread that were started at queyed even if
i am suspending it or what how can i stop this from happening, i.e when the
user selects a vendor then i want to suspend any previous thread which was
getting the list of cities for the previous vendor and get the thread started
with the new vaendor selection. Could the problem be due to the webserivce
that the thread creates? please suggest
Waiting for a suggestion.
Below is the code that i am running.

Creating the thread when the user selects a new vendor from the dropdown :

Private function Vendorchanged()
Try
'Checking to suspend any old thread which might still be acttive from
previous selection
If Not thread_refreshcontact Is Nothing AndAlso
thread_refreshcontact.IsAlive = True Then

thread_refreshcontact.Suspend()

End If

'Beging to re-initialized the thread
thread_refreshcontact = Nothing
thread_refreshcontact = New
Threading.Thread(AddressOf RefreshCity)
thread_refreshcontact.Name = "vendorcity"
thread_refreshcontact.IsBackground = True

thread_refreshcontact.Start()
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End function
'Function being called by the thread above
Private Sub RefreshCity()

Dim custid As Int32 = 0
Dim Dr As DataRow
Dim vendorid As Int32 = 0

Try

DtCity = <CAll the webserivce which returns the datatable with the cities>
Catch ex As Exception

MsgBox(ex.ToString)
End Try

End Sub

Sameer
Aug 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.