473,491 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Async process - Start Subroutine when finished

Hi All,
I'm using this code provided by Michael to run Async process:

http://groups.google.com/group/micro...6d19fccc330588

Now I have a new need. I have to start a Soubroutine when the Async
process is finished.

Many Thanks.

--Marco
Apr 8 '08 #1
4 2444
On Apr 8, 10:43 am, Marcolino <marco.pozzu...@gmail.comwrote:
Hi All,
I'm using this code provided by Michael to run Async process:

http://groups.google.com/group/micro...languages.vb/b...

Now I have a new need. I have to start a Soubroutine when the Async
process is finished.

Many Thanks.

--Marco
You can set up a callback from the BeginInvoke call that will fire
when the async process finishes. Then you can do whatever you need
from that method:

Here's a quick console demo app:

////////////////
Option Strict On

Module Module1

Public Delegate Sub AsyncDelegate()

Sub Main()
Console.WriteLine("Starting")
Dim worker As New AsyncDelegate(AddressOf AsyncMethod)
worker.BeginInvoke(New AsyncCallback(AddressOf
AfterAsyncMethod), Nothing)
Console.WriteLine("Asnyc called")

Console.Read()
End Sub

Private Sub AfterAsyncMethod(ByVal ar As IAsyncResult)
Console.WriteLine("AsyncMethod finished. Do something else")
End Sub

Private Sub AsyncMethod()
Console.WriteLine("Async is working")
'// Simulate work
System.Threading.Thread.Sleep(1500)
Console.WriteLine("Async is done working")
End Sub

End Module
////////////////

Thanks,

Seth Rowe [MVP]
Apr 8 '08 #2
rowe_newsgroups <ro********@yahoo.comwrote in news:424eb9ff-3910-40c0-
8b***************@e39g2000hsf.googlegroups.com:
Private Sub AfterAsyncMethod(ByVal ar As IAsyncResult)
Console.WriteLine("AsyncMethod finished. Do something else")
End Sub
Should call EndInvoke here - to clean up the Async handler?

--
sp**********@rogers.com (Do not e-mail)
Apr 8 '08 #3
On Apr 8, 5:43 pm, Marcolino <marco.pozzu...@gmail.comwrote:
Hi All,
I'm using this code provided by Michael to run Async process:

http://groups.google.com/group/micro...languages.vb/b...

Now I have a new need. I have to start a Soubroutine when the Async
process is finished.

Many Thanks.

--Marco
Marco,
You can also play with BackgroundWorker control and its events such as
RunWorkerCompleted, ProgressChanged events if it helps you.

Regards,

Onur Güzel
Apr 8 '08 #4
On 8 Apr, 18:50, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Apr 8, 5:43 pm, Marcolino <marco.pozzu...@gmail.comwrote:
Hi All,
I'm using this code provided by Michael to run Async process:
http://groups.google.com/group/micro...languages.vb/b...
Now I have a new need. I have to start a Soubroutine when the Async
process is finished.
Many Thanks.
--Marco

Marco,
You can also play with BackgroundWorker control and its events such as
RunWorkerCompleted, ProgressChanged events if it helps you.

Regards,

Onur Güzel
Hi I tryed this:
worker.BeginInvoke(New AsyncCallback(AddressOf AfterAsyncMethod),
Nothing)

but i have a little problem.
During sub AfterAsyncMethod() i need to populate a listview present on
main form. This is not possible because I cannot execute cross tread
operation.
I need that AfterAsyncMethod() will be executed on the main tread of
the application, after my async process is finished.

Thanks a lot
Apr 8 '08 #5

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

Similar topics

12
2862
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
39
789
by: jabailo | last post by:
I am looping through a text file, and with each row, I launch a web service, asynchronously. Before I move on to the next step in the process, I want to make sure that all the web services have...
6
1901
by: Amy L. | last post by:
I am working on a project where I will have a ton of async DNS calls in a console application. I would like to process the results of the Aync calls on the same thread that made the async call. ...
0
4646
by: rob | last post by:
Hello, I have a DOS program that I need to execute from a WinForm application. This DOS program will take a long time to execute. During execution it prints out messages. While the DOS program...
0
2162
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
11
6918
by: ryan | last post by:
Hi, I've omitted a large chunk of the code for clarity but the loop below is how I'm calling a delegate function asynchronously. After I start the each call I'm incrementing a counter and then...
5
3237
by: Paul Hasell | last post by:
Hi, I'm trying to invoke a web method asynchronously but just can't seem to get it to tell me when it has finished! Below is the code I am (currently) using: private void...
6
3793
by: Shak | last post by:
Hi all, Three questions really: 1) The async call to the networkstream's endread() (or even endxxx() in general) blocks. Async calls are made on the threadpool - aren't we advised not to...
5
3415
by: =?Utf-8?B?Z215ZXJz?= | last post by:
Hello, I am attempting to start a cmd.exe process and pass several .vbs scripts (with additional parameters) and then read the output from the scripts and make "notes" in a DataTable (the...
0
6978
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
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7190
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
7360
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
5451
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,...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1392
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
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
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.