[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

VB6 independent process

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
Delta7428
Asked:
Delta7428
  • 6
  • 4
  • 2
2 Solutions
 
LIONKINGCommented:
The simple solution would be to use two timers, have you tried this?
0
 
Delta7428Author Commented:
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
 
LIONKINGCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Delta7428Author Commented:
Thanks.  I'll see how it goes and get back to you.
0
 
Delta7428Author Commented:
Will the processing speed be the same with both timers running or will it be slowed down?
0
 
LIONKINGCommented:
First I wanna know if it works, because this will not behave like multithreading at all. Did it work?
0
 
Delta7428Author Commented:
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
 
LIONKINGCommented:
Test it because if you want them to run at the exact same time then this approach might not work.
0
 
BrianVSoftCommented:
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
 
Delta7428Author Commented:
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
 
BrianVSoftCommented:
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
 
Delta7428Author Commented:
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

Technology Partners: 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!

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now