?
Solved

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

Posted on 2008-10-19
5
Medium Priority
?
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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 86

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 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