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.
Parents
  • 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.
  • 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);
    }
    }
Reply
  • 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);
    }
    }
Children
No Data