Solved

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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