Home All Groups Group Topic Archive Search About

Basic multithreading problem

Author
18 Aug 2006 9:27 PM
sameer
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

Author
18 Aug 2006 11:24 PM
Dennis
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


Show quoteHide quote
"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
Author
21 Aug 2006 1:17 PM
sameer
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

Show quoteHide quote
"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