Home All Groups Group Topic Archive Search About

adding asynchronous support

Author
2 Jan 2006 10:00 PM
matt
i have a VB.net application that connects to the internet to download an xml
file and parse it. It works correctly, but "locks up" until that function
returns.  i want to add asynchronous support, but i'm confused on where i
add the code.  If i want just this function to be in another thread, what do
i add to it?  Also, what do i add to call the function?  thanks,

Author
3 Jan 2006 7:47 AM
Paul Bunting
Something like...

IMPORTS System.Threading

Private Sub frmMe_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        Dim objThread As New Thread(AddressOf fnThreadToRun)
        objThread.IsBackground = True
        objThread.Priority = ThreadPriority.Lowest
        objThread.Name = "MyThread"
        objThread.Start()
end sub

Private Sub fnThreadToRun()
        '.... do something
End Sub

Regards,

P

Show quoteHide quote
"matt" <nospam@nobody.com> wrote in message
news:r-WdnXX_8JMKPyTenZ2dnUVZ_tGdnZ2d@comcast.com...
>i have a VB.net application that connects to the internet to download an
>xml file and parse it. It works correctly, but "locks up" until that
>function returns.  i want to add asynchronous support, but i'm confused on
>where i add the code.  If i want just this function to be in another
>thread, what do i add to it?  Also, what do i add to call the function?
>thanks,
>
Author
12 Jan 2006 10:37 PM
matt
Hey thanks again for getting me started on threads.  I have another
question.  I initiated the thread at the top of my code, and changed the
settings in the "load" sub.  Later in my program, i started the thread, and
it ran fine.  Where i'm having trouble is when it stops and i want to run it
again.  How should i rerun the thread?  When my code detects that the thread
has completed, i tried to use thread.abort, but when i do thread.start
again, i get an error saying the thread has stopped and can't be restarted.
How do i restart it?  Do I reinitiate the thread each time?  I tried that by
initiating the thread once at the begining, and again each time i want it to
run again.  There is one problem, when i look at my program in Task Manager,
each time it runs the thread, it adds a new thread.  Do i have to kill the
thread each time?  Anyway, did i miss the concept of how this works?

Thanks!


Show quoteHide quote
"Paul Bunting" <paul.bunting@archsoftnet.nospamplease> wrote in message
news:en1JtnDEGHA.2648@TK2MSFTNGP11.phx.gbl...
> Something like...
>
> IMPORTS System.Threading
>
> Private Sub frmMe_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>        Dim objThread As New Thread(AddressOf fnThreadToRun)
>        objThread.IsBackground = True
>        objThread.Priority = ThreadPriority.Lowest
>        objThread.Name = "MyThread"
>        objThread.Start()
> end sub
>
> Private Sub fnThreadToRun()
>        '.... do something
> End Sub
>
> Regards,
>
> P
>
> "matt" <nospam@nobody.com> wrote in message
> news:r-WdnXX_8JMKPyTenZ2dnUVZ_tGdnZ2d@comcast.com...
>>i have a VB.net application that connects to the internet to download an
>>xml file and parse it. It works correctly, but "locks up" until that
>>function returns.  i want to add asynchronous support, but i'm confused on
>>where i add the code.  If i want just this function to be in another
>>thread, what do i add to it?  Also, what do i add to call the function?
>>thanks,
>>
>
>
Author
6 Jan 2006 11:17 PM
matt
hey this is great.  It was exactly what i needed.  I played around w/ adding
a second thread to my program.  I learned that is has to be a subroutine and
that you can't "pass parameters" you have to pull them from the thread,
which is fine, and i made a flag so i can check when its done, however, i'm
having trouble getting the parameters it saved.  i have variables and a sub
in a class.  I have an object in my program for hte class, and then another
object that is the subroutine from the class.  the subroutine stores
variables within that class.  i used to pull the variables, they were not
returns, however, now i can't get to these.  here is the basic psuedo code

class1:
var1
var2
sub1()
  do something with var1
  store in var2

myobject = class1
thread = myobject.sub1

myobject.var1 = something
thread.start()
do something with myobject.var2

well, var1 and var2 are empty outside of the thread, but populated inside
the thread.  i used this same approach w/o the thread, and i was able to see
my varibles.  Is there some reason my thread isn't storing variables like
the sub did without the thread?

thanks for your help!

Show quoteHide quote
"Paul Bunting" <paul.bunting@archsoftnet.nospamplease> wrote in message
news:en1JtnDEGHA.2648@TK2MSFTNGP11.phx.gbl...
> Something like...
>
> IMPORTS System.Threading
>
> Private Sub frmMe_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>        Dim objThread As New Thread(AddressOf fnThreadToRun)
>        objThread.IsBackground = True
>        objThread.Priority = ThreadPriority.Lowest
>        objThread.Name = "MyThread"
>        objThread.Start()
> end sub
>
> Private Sub fnThreadToRun()
>        '.... do something
> End Sub
>
> Regards,
>
> P
>
> "matt" <nospam@nobody.com> wrote in message
> news:r-WdnXX_8JMKPyTenZ2dnUVZ_tGdnZ2d@comcast.com...
>>i have a VB.net application that connects to the internet to download an
>>xml file and parse it. It works correctly, but "locks up" until that
>>function returns.  i want to add asynchronous support, but i'm confused on
>>where i add the code.  If i want just this function to be in another
>>thread, what do i add to it?  Also, what do i add to call the function?
>>thanks,
>>
>
>
Author
6 Jan 2006 11:21 PM
matt
disregard that!  i complete forgot that it was in another thread.  it was
trying to use the parameters before it was done processing them.  it works
perfectly!  thanks


Show quoteHide quote
"matt" <nospam@nobody.com> wrote in message
news:_5qdnc1aadUAZyPenZ2dnUVZ_tydnZ2d@comcast.com...
> hey this is great.  It was exactly what i needed.  I played around w/
> adding a second thread to my program.  I learned that is has to be a
> subroutine and that you can't "pass parameters" you have to pull them from
> the thread, which is fine, and i made a flag so i can check when its done,
> however, i'm having trouble getting the parameters it saved.  i have
> variables and a sub in a class.  I have an object in my program for hte
> class, and then another object that is the subroutine from the class.  the
> subroutine stores variables within that class.  i used to pull the
> variables, they were not returns, however, now i can't get to these.  here
> is the basic psuedo code
>
> class1:
> var1
> var2
> sub1()
>  do something with var1
>  store in var2
>
> myobject = class1
> thread = myobject.sub1
>
> myobject.var1 = something
> thread.start()
> do something with myobject.var2
>
> well, var1 and var2 are empty outside of the thread, but populated inside
> the thread.  i used this same approach w/o the thread, and i was able to
> see my varibles.  Is there some reason my thread isn't storing variables
> like the sub did without the thread?
>
> thanks for your help!
>
> "Paul Bunting" <paul.bunting@archsoftnet.nospamplease> wrote in message
> news:en1JtnDEGHA.2648@TK2MSFTNGP11.phx.gbl...
>> Something like...
>>
>> IMPORTS System.Threading
>>
>> Private Sub frmMe_Load(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles MyBase.Load
>>        Dim objThread As New Thread(AddressOf fnThreadToRun)
>>        objThread.IsBackground = True
>>        objThread.Priority = ThreadPriority.Lowest
>>        objThread.Name = "MyThread"
>>        objThread.Start()
>> end sub
>>
>> Private Sub fnThreadToRun()
>>        '.... do something
>> End Sub
>>
>> Regards,
>>
>> P
>>
>> "matt" <nospam@nobody.com> wrote in message
>> news:r-WdnXX_8JMKPyTenZ2dnUVZ_tGdnZ2d@comcast.com...
>>>i have a VB.net application that connects to the internet to download an
>>>xml file and parse it. It works correctly, but "locks up" until that
>>>function returns.  i want to add asynchronous support, but i'm confused
>>>on where i add the code.  If i want just this function to be in another
>>>thread, what do i add to it?  Also, what do i add to call the function?
>>>thanks,
>>>
>>
>>
>
>