none
Windows Application in Windows Service RRS feed

  • Pergunta

  • Hello..

    i have a windows application completed and now i want to add a windows service to the existing application. and i want to call a method of windows application from windows service. i use below code.. plz help

     public partial class Service1 : ServiceBase
        {
            Timer time = new Timer();
            string filename = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\BackupDetails.xml";
            DBinfo1 dbinfo = new DBinfo1();
            public Service1()
            {
                InitializeComponent();
            }
            Process p = new Process();
            protected override void OnStart(string[] args)
            {
                time.Elapsed += new ElapsedEventHandler(OnElapsedTime);
                time.Interval = 1000 * 60;
                time.Start();
                time.Enabled = true;
            }
    
            private void OnElapsedTime(object sender, ElapsedEventArgs e)
            {
                p.StartInfo.FileName = @"C:\Users\Mousmi Muthalib\Documents\Visual Studio 2015\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe";
                p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                p.Start();
            }
    
            
            protected override void OnStop()
            {
                p.Kill();
            }


    Mrs Nishad

    segunda-feira, 1 de junho de 2020 11:08

Respostas

  • Hello..

    i have a windows application completed and now i want to add a windows service to the existing application. and i want to call a method of windows application from windows service. i use below code.. plz help

     public partial class Service1 : ServiceBase
        {
            Timer time = new Timer();
            string filename = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\BackupDetails.xml";
            DBinfo1 dbinfo = new DBinfo1();
            public Service1()
            {
                InitializeComponent();
            }
            Process p = new Process();
            protected override void OnStart(string[] args)
            {
                time.Elapsed += new ElapsedEventHandler(OnElapsedTime);
                time.Interval = 1000 * 60;
                time.Start();
                time.Enabled = true;
            }
    
            private void OnElapsedTime(object sender, ElapsedEventArgs e)
            {
                p.StartInfo.FileName = @"C:\Users\Mousmi Muthalib\Documents\Visual Studio 2015\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe";
                p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                p.Start();
            }
    
            
            protected override void OnStop()
            {
                p.Kill();
            }


    Mrs Nishad

    Hello,

    your source code looks like C#, so ask in a C# forum: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral

    Regards, Guido

    terça-feira, 2 de junho de 2020 06:49
    Moderador

Todas as Respostas

  • Hello,

    See the following, search for 64

    https://stackoverflow.com/questions/5307968/how-can-i-run-an-exe-program-from-a-windows-service-using-c


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    segunda-feira, 1 de junho de 2020 13:06
  • You can't make direct contact with a Windows desktop program from a Windows service in the manner you may be trying to do in executing a method on the running desktop program that I know about.

    There are ways to do it like using WCF.

    Just what is it that you are trying to do? 

    segunda-feira, 1 de junho de 2020 14:28
  • Hello..

    i have a windows application completed and now i want to add a windows service to the existing application. and i want to call a method of windows application from windows service. i use below code.. plz help

     public partial class Service1 : ServiceBase
        {
            Timer time = new Timer();
            string filename = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\BackupDetails.xml";
            DBinfo1 dbinfo = new DBinfo1();
            public Service1()
            {
                InitializeComponent();
            }
            Process p = new Process();
            protected override void OnStart(string[] args)
            {
                time.Elapsed += new ElapsedEventHandler(OnElapsedTime);
                time.Interval = 1000 * 60;
                time.Start();
                time.Enabled = true;
            }
    
            private void OnElapsedTime(object sender, ElapsedEventArgs e)
            {
                p.StartInfo.FileName = @"C:\Users\Mousmi Muthalib\Documents\Visual Studio 2015\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe";
                p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                p.Start();
            }
    
            
            protected override void OnStop()
            {
                p.Kill();
            }


    Mrs Nishad

    Hello,

    your source code looks like C#, so ask in a C# forum: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral

    Regards, Guido

    terça-feira, 2 de junho de 2020 06:49
    Moderador
  • i tried what i told above..its not working so i changed..

    now i create a windows service project named scheduler. and in that i add windows form . Now i want to call a function from windows form in windows service. 

    //this is my service Class  
      public partial class Service1 : ServiceBase
        {
            Timer time = new Timer();
            string filename = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\BackupDetails.xml";
            Form1 frm = new ScheduleService.Form1();
            public Service1()
            {
                InitializeComponent();
            }
            Process p = new Process();
            protected override void OnStart(string[] args)
            {
                time.Elapsed += new ElapsedEventHandler(OnElapsedTime);
                time.Interval = 1000 * 60;
                time.Start();
                time.Enabled = true;
            }
    
            private void OnElapsedTime(object sender, ElapsedEventArgs e)
            {
                frm.notifyIcon1.ShowBalloonTip(5);// i want to display notify icon too
                frm.ReadXML();
                
            }

    Mrs Nishad

    terça-feira, 2 de junho de 2020 06:54