Solved

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

Posted on 2008-10-19
5
289 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 86

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 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

Independent Software Vendors: 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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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