Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one simple system Tray Application which runs continuously and Tries to launch another Windows application which has a UI. It lets user interact with it and then closes the application. after some time interval it tries to do the same. It works properly for few transactions but then it doesn't launch the application. when i checked the task manager i found that after few successful opening and closing the system tray app launches the app with ui as the background process. Hence user is unable to see the app getting launched. I tried adding exception to the antivirus for both the exes and also i have tried different methods to close and open the exes. I also checked the windows logs to see if there was any exception. There was no exception in my system tray app also. I am not able to in point the exact problem of this behavior as it randomly launches the app as the background process.

any help with this problem will be much appreciated.

To Launch the app: I use com component provided by the software company to interact with the application. on creating object of this class application gets launched and this object is further used to do few operations on the app. I have also tried launching the application with process.start() but it had same issue.

To close the App:

C#
if (isRunning())
            {
                Process[] p = Process.GetProcessesByName("mdw");
                if (p.Length > 0)
                    p[0].CloseMainWindow();
                PEHRsLibrary.writeTextFile(DateTime.Now + " : Closing Main Window of Application");
                System.Threading.Thread.Sleep(2000);
            }

I have also tried Process.kill to close the app which used to give access denied error after few launching-closing.

I am disposing the object onQuitevent of the application MDW.OnQuit -= OnQuitDelegate;
C#
//MDW.OnValidatePatient -= OnValidatePatientDelegate;

// loop through release until reference count is zero
while (Marshal.ReleaseComObject(MDW) > 0 )
{
    PEHRsLibrary.writeTextFile(string.Format("{0} : Inside ReleaseMDW, releasing all dependent resources of MDW application ", DateTime.Now));
}

MDW = null;


What I have tried:

Tried using different methods to close and start the application.
Posted
Updated 12-Sep-17 21:01pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900