Solved

VB6 independent process

Posted on 2011-02-12
12
347 Views
Last Modified: 2012-05-11
I have a vb6 program that with a timer that does the following:

1)      Queries the database, updates and appends records
2)      Copies images from one server to another

I need step 2 to run independently.  i.e. I do not want step 1 to wait until step 2 completes before running again.  How do I do this in VB6?  I have researched multithreading and am not clear on it or if it is truly possible in VB6?  What about Activex?  I do not have experience with either one.  Can I do this with a timer?
0
Comment
Question by:Delta7428
  • 6
  • 4
  • 2
12 Comments
 
LVL 13

Expert Comment

by:LIONKING
Comment Utility
The simple solution would be to use two timers, have you tried this?
0
 

Author Comment

by:Delta7428
Comment Utility
No I haven't tried two timers.  If I started a second timer within the first timer, would they run independetly or would I need to start them independtly when the project loaded or something.
0
 
LVL 13

Expert Comment

by:LIONKING
Comment Utility
Start them independently one start after the other, and place your code accordingly in each timer. You can also use different delays for each timer if needed.
0
 

Author Comment

by:Delta7428
Comment Utility
Thanks.  I'll see how it goes and get back to you.
0
 

Author Comment

by:Delta7428
Comment Utility
Will the processing speed be the same with both timers running or will it be slowed down?
0
 
LVL 13

Expert Comment

by:LIONKING
Comment Utility
First I wanna know if it works, because this will not behave like multithreading at all. Did it work?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:Delta7428
Comment Utility
I'm just now working putting the image processing in a separate exe and plan to call one of the exe's from one of the timer events.  The exe willl move a bunch of images and resize, and convert some of them.   I will let you know as soon as I get done and test it if it works.  I need both timer events to run simulataneously...  
0
 
LVL 13

Expert Comment

by:LIONKING
Comment Utility
Test it because if you want them to run at the exact same time then this approach might not work.
0
 
LVL 5

Accepted Solution

by:
BrianVSoft earned 500 total points
Comment Utility
I agree with the two exe idea..
You only need one timer in the main exe - It first Shells the second exe that does the images then calls the sub that updates the database..
The Main exe doesn't wait for the 2nd exe to finish - it drops straight thru to the second task.
So both tasks run together..
It is wise to check for the presence of the small exe before Shelling it again on the next timer event (in case it hasn't finished yet) That's a simple process..
0
 

Author Comment

by:Delta7428
Comment Utility
BrianVSoft, I'll try it with one timer.  

I tried adding a timer and Shelling the exe from there.  It doesn't work.  The second timer never fires.  Actually I have 3 timers.  The first one only flashes a "tick" label on the screen letting the user know it is running.  The tick timer and the first process timer fires, but the 3rd one does not.

How do I check for the presence of the exe to see if it has finished yet?

0
 
LVL 5

Assisted Solution

by:BrianVSoft
BrianVSoft earned 500 total points
Comment Utility
If a Timer never gets to fire, it is usually because the App is performing a long process in a loop that doesn't include a DoEvents.. (Any loop that can process for more than a second or two should include a DoEvents.)

There are two ways to ensure a Shelled App doesn't run twice..
1. In the Apps Form_Load event, test for App.Previous Instance and do an "End" if it is already running..
Eg. If App.PrevInstance Then End
2. Use the FindWindow function to see if it is already running..
You need to know the TITLE of the main form. eg. "MyTitle"
Eg.
  If FindWindow("ThunderRT6FormDC", "MyTitle") = 0 Then..
    Shell the App..
You need to declare this function.. Eg.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
The "ThunderRT6FormDC" is the class name of VB6 type Apps.
0
 

Author Comment

by:Delta7428
Comment Utility
BrianVSoft, Before I got your post,  I ran it without testing for the presence of the exe first ... the exe that processes the images did not finish.  It probably executed again before it completed.  Is that why?  I'll try your code above and see if that helps.

Also, it ended up I needed 2 exe's.  I'll add it to both.
Private Sub Form_Load()
    mdtTimeNext = Now
    With TimerFlash
        .Interval = 1000 '1 second
        .Enabled = False
    End With
    With TimerFlipControl
        .Interval = 1000 '1 second
        .Enabled = False
    End With
End Sub

Private Sub TimerFlipControl_Timer()
    If Now > mdtTimeNext Then
        '>>Add 5 minutes to current time
        mdtTimeNext = DateAdd("n", 5, Now)
        
        '>process ungrouped orders
        FlipControl
        
         'process grouped orders
        Dim RetVal
        RetVal = Shell("\\mwafs\mis\mis\Projects_Prod\FujiFlip\FujiFlip_Grouped.exe", 1)
        
        '>>Convert and copy images
        RetVal = Shell("\\mwafs\mis\mis\Projects_Prod\FujiFlip\FujiLabelPrint_Images.exe", 1)
    End If
End Sub
Private Sub TimerFlash_Timer()

    With Me.lblMessage
        If .Caption = "" Then
            .Caption = sTimerMessage
        Else
            .Caption = ""
        End If
        
    End With

End Sub

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

728 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

9 Experts available now in Live!

Get 1:1 Help Now