Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Showing Interactive services detection window when trying to run .exe on Windowservice Onstart()method. Once we clcik on show message then the exe(console application) shows in a separate window and windows desktop will not appear.Below is the simple code i tried. Any idea to solve this .

C#
public partial class ScheduledService : ServiceBase
   {
       //TimerCallback timer = new TimerCallback(DBMethod);
        System.Timers.Timer timer = new System.Timers.Timer();

       public ScheduledService()
       {
           InitializeComponent();
       }

       protected override void OnStart(string[] args)
       {
          // TraceService("start service");

           //handle Elapsed event
           timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);

          // ////This statement is used to set interval to 1 minute (= 60,000 milliseconds)

           timer.Interval = 1000;

          // ////enabling the timer
           timer.Enabled = true;
           try
           {
               Process p = new Process();
               p.StartInfo.WorkingDirectory = @"C:\Documents\Visual Studio 2010\Projects\palindrome\palindrome\bin\Debug";
               p.StartInfo.FileName = "palindrome.exe";
               p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;  // Change as needed
               p.Start();
               p.WaitForExit(300000); // Synchronous timed wait
           }
           catch (Exception ex)
           {
             //  throw new ApplicationException(string.Format("Unable to start process: {0}\r\nException:{1}", processExecutable, ex.Message));
           }


       }
Posted

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