hexagon logo

VB code/ If a program is running

Does anyone know what code would be used to find out if a program is currently running in PC-Dmis? I wrote some code to automate the execution process and if I use it while a program is running, it closes the program and opens the new program while the original program continues to run. (Not sure for how long though. I stopped it after I tested it.)
Parents
  • This was my "Fix"

    Private Sub File_Explorer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim varSourceopen As String = "Opened"
            If Process.GetProcessesByName("PCDLRN").Length = 0 Then
                Process.Start("C:\Program Files\Hexagon\PC-DMIS 2017 R2 64-bit\PCDLRN.exe", "/o")
            End If
    
            Do
                If Process.GetProcessesByName("PCDLRN").Length > 0 Then
                    PCDApp = CreateObject("PCDLRN.Application")
                    AppEvent = PCDApp.ApplicationEvents
                    PCDApp.OperatorMode = True
                    Exit Do
                Else
                    Threading.Thread.Sleep(1000)
                End If
            Loop
    
            PCD_Create(varSourceopen)
    
        End Sub


    It's basically opening Operator mode through the ,exe and passing the operator parameter. Then it waits until the app shows up in tasks then attaches. Seems to work good so far. But now I'm running into another issue. I'm trying to disable 2 buttons upon the start of a program to ensure another program will not be opened while another is running.

    Private Sub AppEvents_OnStartExecution(ByVal PartProg As PartProgram) Handles AppEvent.OnStartExecution
            ' Event subroutine. This activates when you START EXECUTION of the part program.
            Button1.Enabled = False
            Button2.Enabled = False
            Me.Close()
        End Sub


    No matter what I tried, when the event is triggered only one line is read and the rest are skipped. I can put the same code in a button and it works fine. I tried having it show 3 message boxes after the event triggered but the first one shows, then once I hit ok I get a server busy error message. If anyone else uses onstartexecution, have they seen the same thing?
    Once I get this button things figured out I think I will be good to go
Reply
  • This was my "Fix"

    Private Sub File_Explorer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim varSourceopen As String = "Opened"
            If Process.GetProcessesByName("PCDLRN").Length = 0 Then
                Process.Start("C:\Program Files\Hexagon\PC-DMIS 2017 R2 64-bit\PCDLRN.exe", "/o")
            End If
    
            Do
                If Process.GetProcessesByName("PCDLRN").Length > 0 Then
                    PCDApp = CreateObject("PCDLRN.Application")
                    AppEvent = PCDApp.ApplicationEvents
                    PCDApp.OperatorMode = True
                    Exit Do
                Else
                    Threading.Thread.Sleep(1000)
                End If
            Loop
    
            PCD_Create(varSourceopen)
    
        End Sub


    It's basically opening Operator mode through the ,exe and passing the operator parameter. Then it waits until the app shows up in tasks then attaches. Seems to work good so far. But now I'm running into another issue. I'm trying to disable 2 buttons upon the start of a program to ensure another program will not be opened while another is running.

    Private Sub AppEvents_OnStartExecution(ByVal PartProg As PartProgram) Handles AppEvent.OnStartExecution
            ' Event subroutine. This activates when you START EXECUTION of the part program.
            Button1.Enabled = False
            Button2.Enabled = False
            Me.Close()
        End Sub


    No matter what I tried, when the event is triggered only one line is read and the rest are skipped. I can put the same code in a button and it works fine. I tried having it show 3 message boxes after the event triggered but the first one shows, then once I hit ok I get a server busy error message. If anyone else uses onstartexecution, have they seen the same thing?
    Once I get this button things figured out I think I will be good to go
Children