hexagon logo

Events only firing one time within C# application

I have a C# application that initializes an instance of PCDLRN.dll and adds a bunch of ApplicationEvents to it. On the first execution of the program everything works fine but after that the events don't seem to be firing. As far as I can tell the PCDLRN.Application is not null, and the ActivePartProgram also isn't null. However, when I hit execute button in PC-DMIS a second time I don't see anything from the event handlers I attached to the ApplicationEvents object. Any suggestions would be greatly appreciated.
  • Just recently had this same occurrence when executing the application from within PC-DMIS customize menu. The application was created using NET 7.0. Then recreated the application using Framework 4.8 with no issues. I haven't had a chance to determine what the cause was yet.
  • I figured out my issue and it has nothing to do with PC-DMIS. It has to do with some of our internal logging code. Sorry I can be of any help.
  • Glad you found the source of the issue. For me I just switched over to using the 4.8 framework instead of NET 7.0 and everything is working correctly. Usually, the NET 7.0 runs faster than 4.8 framework and it's the latest of the Dot NET family. I find less errors using the 4.8 framework with the PCDLRN.DLL.
  • So after a few more days of working on this issue I think I have more information about what is happening. To me it seems like I might be running into either a memory leak or race condition for the PCDLRN.INTEROP.dll file with my C# application and PC-DMIS itself. I have spent almost 30 hours trying to figure out what is going on. I have tried using threading, Synchronization Context, logging to a file, to the console, to a remote telemetry stream. The first execution of a program works perfectly, sometimes events fire on the second execution but not every event; somewhere in the middle of the program it just stops. I have tried slowing down the animation, waiting 5 minutes between program executions... I have no other ideas. I will try anything at this point. COM objects are so difficult to debug. Does anyone have any tips?
  • At this point the only thing I could do is examine the code and test it to see if I can find what could be the cause.
  • Update: I was trying to serialize and log information within an event handler and I think this was taking too long. So instead I have created a thread safe queue that I am using to store event information. Then in my application's main I check to see if there are events in the Queue and I log them or else I sleep for 100 milliseconds. This works perfectly now.

    var session = new PcDmisSession();
    session.StartPcDmisApplicationSession();
    session.SetApplicationVisibility(true);

    while (true)
    {
    if (session.Events.TryDequeue(out var eventObject))
    {
    Flog.Emit("pc-dmis", eventObject);
    }
    else
    {
    Thread.Sleep(100);
    }

    if (!session.IsPcDmisOpen())
    {
    Console.WriteLine("Press any key to open PC-DMIS");
    Console.ReadKey();
    session.SetApplicationVisibility(true);
    }
    }
  • Thank you for the updated information. Glad to hear that you were able to solve the issue. I will have to keep this in mind for when I run into a similar issue.