473,505 Members | 16,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding asynchronous support

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,
Jan 2 '06 #1
5 1114
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" <no****@nobody.com> wrote in message
news:r-******************************@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,

Jan 3 '06 #2
Matt,

If you use version 2005 have than a look at backgroundworker

http://msdn2.microsoft.com/en-us/library/c8dcext2.aspx

The demonstrations are there

Cor
Jan 3 '06 #3
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" <pa**********@archsoftnet.nospamplease> wrote in message
news:en**************@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" <no****@nobody.com> wrote in message
news:r-******************************@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,


Jan 6 '06 #4
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
"matt" <no****@nobody.com> wrote in message
news:_5******************************@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" <pa**********@archsoftnet.nospamplease> wrote in message
news:en**************@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" <no****@nobody.com> wrote in message
news:r-******************************@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,



Jan 7 '06 #5
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!
"Paul Bunting" <pa**********@archsoftnet.nospamplease> wrote in message
news:en**************@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" <no****@nobody.com> wrote in message
news:r-******************************@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,


Jan 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1418
by: Thomas Nielsen | last post by:
Hi, I need to make a web page that wait for 3 asynchronous processes to finish. So I am considering these options 1) Poll the status of the processes from the web page using the "REFRESH"...
5
15491
by: HugeBob | last post by:
Hi All, I've got a question about Asynchronous vs Synchronous mode with the XMLHttpRequest object. What are the ramifications of using one mode vs the other? If the script uses Asynchronous...
4
4526
by: MaxMax | last post by:
I'm using HttpWebRequest. It seems that all the callback called from HttpWebRequest are in another thread (not in the "original" thread). Now my problem is that the "original" thread is the thread...
2
2193
by: Oriane | last post by:
Hello there, I use an Ajax slider extender and I'm try to find a workaround to a known (http://forums.asp.net/p/1092702/2681110.aspx) "bug" of the slider control from the Ajax Control Toolkit....
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.