Solved

How do I start multiple subs or functions at the same time?

Posted on 2008-10-19
5
285 Views
Last Modified: 2012-06-22
I have a button
and I have 4 subs
I want them all to start at the SAME TIME.
It will only run one at a time.
I tried putting them into 4 timers and starting all 4 timers - but it just goes all hay-wire on me.
I know there is an easy way to do this.
I just cant get it!

like in batch file you can do:
START photogroup_1.bat
START photogroup_2.bat
ect.
and it will just open 2 cmd windows an they all start
trying to do this in VB.
I want all 4 to just fire off at the same time!

Thanks in Advanced...
button1_Click ()

'launch PhotoSub1

PhotoGroup01()

'launch PhotoSub2

PhotoGroup02()

'launch PhotoSub3

PhotoGroup03()

'launch PhotoSub4

PhotoGroup04()

End Sub

Open in new window

0
Comment
Question by:CanvasYou
  • 3
  • 2
5 Comments
 

Author Comment

by:CanvasYou
ID: 22754051
am I not supposed to use sub routines for this?
I understand that the sub has to run linear - but can't i have all 4 subs start at once and basically be like 4 linear branches of code going off doing stuff all at the same time?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 22754169
Like below...BUT you should not update the GUI from any of the PhotoGroupXX() methods using this simplistic approach.
Imports System.Threading

Public Class Form1
 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim T As Thread

        T = New Thread(AddressOf PhotoGroup01)

        T.Start()

        T = New Thread(AddressOf PhotoGroup02)

        T.Start()

        T = New Thread(AddressOf PhotoGroup03)

        T.Start()

        T = New Thread(AddressOf PhotoGroup04)

        T.Start()

    End Sub
 

    Private Sub PhotoGroup01()
 

    End Sub
 

    Private Sub PhotoGroup02()
 

    End Sub
 

    Private Sub PhotoGroup03()
 

    End Sub
 

    Private Sub PhotoGroup04()
 

    End Sub
 

End Class

Open in new window

0
 

Author Comment

by:CanvasYou
ID: 22754202
Alright I will give it a try!
I am not updating the GUI - each SUB just copies files.
I noticed that when the subs are running 2 things:

1.) the GUI will refresh for about 2 mins of copying files - then it just freezes - it is still copying files though. But the GUI and progres bars are not refreshing -
Like it is taking up so much resources - if the screen saver comes on while it is running - then i move the mouse to bring the screen back on - the actual app is just a white box (the whole form) like it does not have the memory to refresh. I have DUal core processor and 2 Gig RAM though.

2.) the page file grows really rapidly - will this be a problem? shouldn't it refresh or clear itself w/ VB automatically -
I know this is a sep. issue - but I would appreciate it if you could help me out!
Thanks
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 22754222
The Refresh() issue should go away when the subs are run in their own threads as shown above.  The reason it freezes and becomes a white box is because you are monopolizing the main UI thread and not allowing it to process user interaction and normal windows messages.

Not sure about the page file issue...that seems like it should resolve itself after the operation is complete.
0
 

Author Closing Comment

by:CanvasYou
ID: 31507664
I really appreciate it. I have had that issue w/ the refresh happening for quite some time.
Thanks a lot!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now