Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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