hexagon logo

Automation Issue with .NET

When opening and executing PC-DMIS programs from a Windows VB.Net application, on SOME machines SOME of the time, the main PC-DMIS window will not display.
Only the PC-DMIS Execution Window is displayed - PC-DMIS User Prompts are essentially unavailable. In this case, closing PC-DMIS via task manager is the only solution.

My open and Execute construct are (essentially) the following:

PCDMISapplication = New PCDLRN.Application
PCDprograms = PCDMISapplication.PartPrograms
PCDMISapplication.Visible = True
PCDpartPrg = PCDMISprograms.Open(pathAndFilename, machineName)
Threading.Thread.Sleep(2000) ' Wait while program opens
PCDMISapplication.WaitUntilReady(200)
PCDpartPrg.Visible = True
PCDpartPrg.EXECUTE()


I suspect the solution is to add a variable the Thread.Sleep() and WaitUntilReady() methods and increase the times until this stops. But that doesn't explain the random nature.

Another Thought: Since I'm also handling some PartProgram Object events, I'm tempted to put the PCDpartPrg.Visible = True in a regularly fired event. But this seems like wikkid overkill. Again, I'd just like to understand the nature of this random problem.

Any thoughts?

Thanks,
Dan (in DFW - supposedly)
Parents
  • Hey Dan,

    I don't recall ever running into the issue your having, but there are a couple of things I do differently that may help you:

    1. Wait until PC-DMIS is fully instantiated and initialized before setting any application properties or sending commands;
    2. Use COM methods (CreateObject/GetObject) as mentioned by NinjaBadger - I've experienced some strange behaviors when trying to use PCDLRN's New() constructor.



    An abbreviated version of my start functions would look like this:

    [COLOR="#008000"]'Application property scoped as needed[/COLOR]
    [COLOR="#0000FF"]Public Property[/COLOR] pcdApp [COLOR="#0000FF"]As[/COLOR] PCDLRN.[COLOR="#008080"]Application[/COLOR]
    
    
    [COLOR="#0000FF"]Public Function[/COLOR] StartPCDMIS(IsVisible [COLOR="#0000FF"]As Boolean[/COLOR]) [COLOR="#0000FF"]As Boolean[/COLOR]
    
       [COLOR="#0000FF"]Try[/COLOR]
          [COLOR="#008000"]'GetObject used to start PC-DMIS or grab an existing instance[/COLOR]
          [B]pcdApp = [COLOR="#0000FF"]DirectCast[/COLOR](GetObject([COLOR="#B22222"]""[/COLOR],[COLOR="#B22222"]"PCDLRN.Application"[/COLOR]), PCDLRN.[COLOR="#008080"]Application[/COLOR])[/B]
    
          pcdApp.WaitUntilReady(60)
          Threading.Thread.Sleep(2000)
    
          [COLOR="#0000FF"]If[/COLOR] pcdApp [COLOR="#0000FF"]Is Nothing Then Return False[/COLOR]
    
          [COLOR="#008000"]'Visible property not addressed until after WaitUntilReady and Thread.Sleep[/COLOR]
          [B]pcdApp.Visible = IsVisible[/B]
    
          [COLOR="#0000FF"]Return[/COLOR] ([COLOR="#0000FF"]Not[/COLOR] pcdApp [COLOR="#0000FF"]Is Nothing[/COLOR])
    
       [COLOR="#0000FF"]Catch[/COLOR] ex [COLOR="#0000FF"]As Exception[/COLOR]
          [COLOR="#0000FF"]Throw New[/COLOR] [COLOR="#008080"]Exception[/COLOR]([COLOR="#B22222"]"Start PC-DMIS : "[/COLOR] + ex.Message)
       [COLOR="#0000FF"]End Try[/COLOR]
    
    [COLOR="#0000FF"]End Function[/COLOR]
Reply
  • Hey Dan,

    I don't recall ever running into the issue your having, but there are a couple of things I do differently that may help you:

    1. Wait until PC-DMIS is fully instantiated and initialized before setting any application properties or sending commands;
    2. Use COM methods (CreateObject/GetObject) as mentioned by NinjaBadger - I've experienced some strange behaviors when trying to use PCDLRN's New() constructor.



    An abbreviated version of my start functions would look like this:

    [COLOR="#008000"]'Application property scoped as needed[/COLOR]
    [COLOR="#0000FF"]Public Property[/COLOR] pcdApp [COLOR="#0000FF"]As[/COLOR] PCDLRN.[COLOR="#008080"]Application[/COLOR]
    
    
    [COLOR="#0000FF"]Public Function[/COLOR] StartPCDMIS(IsVisible [COLOR="#0000FF"]As Boolean[/COLOR]) [COLOR="#0000FF"]As Boolean[/COLOR]
    
       [COLOR="#0000FF"]Try[/COLOR]
          [COLOR="#008000"]'GetObject used to start PC-DMIS or grab an existing instance[/COLOR]
          [B]pcdApp = [COLOR="#0000FF"]DirectCast[/COLOR](GetObject([COLOR="#B22222"]""[/COLOR],[COLOR="#B22222"]"PCDLRN.Application"[/COLOR]), PCDLRN.[COLOR="#008080"]Application[/COLOR])[/B]
    
          pcdApp.WaitUntilReady(60)
          Threading.Thread.Sleep(2000)
    
          [COLOR="#0000FF"]If[/COLOR] pcdApp [COLOR="#0000FF"]Is Nothing Then Return False[/COLOR]
    
          [COLOR="#008000"]'Visible property not addressed until after WaitUntilReady and Thread.Sleep[/COLOR]
          [B]pcdApp.Visible = IsVisible[/B]
    
          [COLOR="#0000FF"]Return[/COLOR] ([COLOR="#0000FF"]Not[/COLOR] pcdApp [COLOR="#0000FF"]Is Nothing[/COLOR])
    
       [COLOR="#0000FF"]Catch[/COLOR] ex [COLOR="#0000FF"]As Exception[/COLOR]
          [COLOR="#0000FF"]Throw New[/COLOR] [COLOR="#008080"]Exception[/COLOR]([COLOR="#B22222"]"Start PC-DMIS : "[/COLOR] + ex.Message)
       [COLOR="#0000FF"]End Try[/COLOR]
    
    [COLOR="#0000FF"]End Function[/COLOR]
Children
No Data