How to Run my .exe file or Application in the Background using .NET Application like explorer.exe file is Running always in the Background...(you can see in task Manager..)

Hi ,

This is Sundar , i want to develope one small Application in windows or web ,that should send the mail continiously according to at what time scheduled in the application and that should Running in the Background always like windows service,SQL server ........

so , please help me ......................

0
Sundar123
11/13/2008 4:19:49 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

14 Replies
4423 Views

Similar Articles

[PageSpeed] 5

 what;s the problem if you develop an windows service and install it in your system.

  http://www.15seconds.com/issue/021007.htm


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
-1
ramireddyindia
11/13/2008 7:06:50 AM

 see, i have created the Windows services and which is running in the Background also but the mail is not going, if i manualy click that .EXE file ,then Mails are going .... so what is the Problems................

 

Code is Here,

---------------------

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Net.Mail;
using System.Web.Mail;
//using System.Windows.Forms;
using System.Net;

namespace WindowsService
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {
          
         timer1.Enabled = true;
         timer1.Start();
        }

        protected override void OnStop()
        {
            // TODO: Add code here to perform any tear-down necessary to stop your service.
            timer1.Enabled = false;
            timer1.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            SmtpClient client = new SmtpClient("smtp.gmail.com"); //pop.gmail.com  smtp.gmail.com
            client.EnableSsl = true;
            MailAddress from = new MailAddress("sundar@armaninfotech.com", "[ Your full name here]");
            MailAddress to = new MailAddress("shailesh@armaninfotech.com", "Your recepient name");
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
            message.Body = "This is a test For Checking the Windows Service........ ";
            message.Subject = "This is For Checking the Windows Service is Running in the Background..Test By sundar........ ";
            NetworkCredential myCreds = new NetworkCredential("sundar@armaninfotech.com", "sundar123", "");
            client.Credentials = myCreds;
            try
            {
                client.Send(message);
                //MessageBox.Show("Message Has Been Sent Successfully!");
            }
            catch (Exception ex)
            {
                // Console.WriteLine("Exception is:" + ex.ToString());
                //MessageBox.Show("Exception is:" + ex.ToString());
            }  

         
        }
    }
}

-------------------------

then i installed  this .exe file using InstallUtil.....then i started my service.................

 

0
Sundar123
11/13/2008 7:42:06 AM

 are you sure you started service.

go to start->run-> services.msc->select your service written-> and check its status, if it not started, start it.

 

and also, you can debug that by writing some sort of checkcommands to eventlog in some methods.

  EventLog.WriteEntry(".Service started");         // keep this line in start method

   EventLog.WriteEntry(".Timer event fired");   // keep this in timer_tick event

 

this is my previously written service code part

 

   SqlConnection PubsConn;
        private System.Timers.Timer timer = null;
        public RemainderService()  // this is the constructor
        {
            InitializeComponent();
            string servicepollinterval = "10000";
            double interval = 10000;
            try
            {
                interval = Convert.ToDouble(servicepollinterval);
            }
            catch (Exception) { }
            timer = new System.Timers.Timer(interval);
            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.ServiceTimer_Tick);

        }
        protected override void OnStart(string[] args)
        {
            EventLog.WriteEntry(ServiceName + " Service started1");
            EventLog.WriteEntry(ServiceName + " Service started2");
            EventLog.WriteEntry(ServiceName + " Before Timer Initialized.");

            EventLog.WriteEntry(ServiceName + " Timer Initialized.");
            timer.Enabled = true;
        }


        protected override void OnStop()
        {
            EventLog.WriteEntry(ServiceName + " Service stopped");
            timer.Enabled = false;
        }

        protected override void OnPause()
        {
            EventLog.WriteEntry(ServiceName + " Service paused");
            timer.Enabled = false;
        }

        protected override void OnContinue()
        {
            EventLog.WriteEntry(ServiceName + " Service continued");
            timer.Enabled = true;
        }

        private void ServiceTimer_Tick(object sender, System.Timers.ElapsedEventArgs e)
        {
            this.timer.Stop();
            RunCommands();
            this.timer.Start();
        }
  

 

 


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
11/13/2008 7:51:44 AM
0
Haissam
11/13/2008 7:57:43 AM
you did not get my question proberly... i want to Run my .exe in the Background  like windows services..................(eg...Iexplore.exe)....that mean it should executing always in Background of OS ...........
0
Sundar123
11/13/2008 9:23:03 AM

see , I have Started My Services also, it is showing like Started ...........but i did not get Mails...............

0
Sundar123
11/13/2008 10:00:52 AM

add the debug statements of writing to eventlog in timer start ,stop events and also that timer_tick event as i suggested in my previous post

then check your event log and tell me the results.


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
11/13/2008 10:06:20 AM

 After Added this line only--------> EventLog.WriteEntry(".Service started");

--its working fine , tell me what is the Reason & use of those lines becase i am new to this functionality.................

 Thanks ............................

0
Sundar123
11/13/2008 11:49:46 AM

first time only mails are going after that my services is stoped Automatically & so this Event (timer1_Tick) is not Running ,what is the problem........

Code : ----------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Net.Mail;
using System.Web.Mail;
//using System.Windows.Forms;
using System.Net;

namespace WindowsService
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {
            timer1.Enabled = true;
            timer1.Start();

            EventLog.WriteEntry("OnStart---->.Service started");         // keep this line in start method

            EventLog.WriteEntry("OnStart---->.Timer event fired");   // keep this in timer_tick event


            // TODO: Add code here to start your service.
            SmtpClient client = new SmtpClient("smtp.gmail.com"); //pop.gmail.com  smtp.gmail.com
            client.EnableSsl = true;
            MailAddress from = new MailAddress("sundar@armaninfotech.com", "[ Your full name here]");
            MailAddress to = new MailAddress("shailesh@armaninfotech.com", "Your recepient name");
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
            message.Body = "This is a test e-mail message sent using gmail as a relay server ";
            message.Subject = "Gmail test email with SSL and Credentials";
            NetworkCredential myCreds = new NetworkCredential("sundar@armaninfotech.com", "sundar123", "");
            client.Credentials = myCreds;
            try
            {
                client.Send(message);
                //MessageBox.Show("Message Has Been Sent Successfully!");
            }
            catch (Exception ex)
            {
                // Console.WriteLine("Exception is:" + ex.ToString());
                //MessageBox.Show("Exception is:" + ex.ToString());
            } 


        }

        protected override void OnStop()
        {
            EventLog.WriteEntry("OnStop----->.Service started");         // keep this line in start method

            EventLog.WriteEntry("OnStop------>.Timer event fired");   // keep this in timer_tick event

            // TODO: Add code here to perform any tear-down necessary to stop your service.
            timer1.Enabled = false;
            timer1.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //timer1.Enabled = false;
            //timer1.Stop();
            timer1.Enabled = true;
            timer1.Start();

            EventLog.WriteEntry("timer1_Tick------>.Service started");         // keep this line in start method

            EventLog.WriteEntry("timer1_Tick------->.Timer event fired");   // keep this in timer_tick event
           
            SmtpClient client = new SmtpClient("smtp.gmail.com"); //pop.gmail.com  smtp.gmail.com
            client.EnableSsl = true;
            MailAddress from = new MailAddress("sundar@armaninfotech.com", "[ Your full name here]");
            MailAddress to = new MailAddress("shailesh@armaninfotech.com", "Your recepient name");
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
            message.Body = "This is a test For Checking the Windows Service........ ";
            message.Subject = "This is For Checking the Windows Service is Running in the Background..Test By sundar........ ";
            NetworkCredential myCreds = new NetworkCredential("sundar@armaninfotech.com", "sundar123", "");
            client.Credentials = myCreds;
            try
            {
                client.Send(message);
                //MessageBox.Show("Message Has Been Sent Successfully!");
            }
            catch (Exception ex)
            {
                // Console.WriteLine("Exception is:" + ex.ToString());
                //MessageBox.Show("Exception is:" + ex.ToString());
            } 

        
        }
    }
}
 

1
Sundar123
11/13/2008 12:44:51 PM

Sundar123:
first time only mails are going after that my services is stoped Automatically & so this Event (timer1_Tick) is not Running ,what is the problem........

because you write the mail code in timer start event. when the application runs, timer started, that means timer start event will fire. and your code is executing. but the timer tick event is not firing because of the reasons i think you didn't set interval and declare its timer tick event. so only once its sending mails. and service stopped, reason for this is i am not sure. but previously i heard, that service will stop if it has been idle. in your case its idle. so, its  happening like that.


What my advice is better, to go to this URL and design the service as said in that URL. I too implement 6 services using that URL in 10 Minutes.

   http://www.15seconds.com/issue/021007.htm


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
11/14/2008 3:25:09 AM

 I tried your Code & put the send Mail Codes inside the Start() & Timer_ticler() also but which is not executing of Mailing parts ....... so give me the solution & Reply me.........

0
Sundar123
11/15/2008 4:07:00 AM

 i changed your code and try this.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Net.Mail;
using System.Web.Mail;
//using System.Windows.Forms;
using System.Net;

namespace WindowsService
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
	    string servicepollinterval = "10000";
            double interval = 10000;
            try
            {
                interval = Convert.ToDouble(servicepollinterval);
            }
            catch (Exception) { }
            timer = new System.Timers.Timer(interval);
            timer.Elapsed += new System.Timers.ElapsedEventHandler(this.ServiceTimer_Tick);

        }
        protected override void OnStart(string[] args)
        {
            EventLog.WriteEntry(ServiceName + " Service started1");
            EventLog.WriteEntry(ServiceName + " Service started2");
            EventLog.WriteEntry(ServiceName + " Before Timer Initialized.");

            EventLog.WriteEntry(ServiceName + " Timer Initialized.");
            timer.Enabled = true;
        }


        protected override void OnStop()
        {
            EventLog.WriteEntry(ServiceName + " Service stopped");
            timer.Enabled = false;
        }

        protected override void OnPause()
        {
            EventLog.WriteEntry(ServiceName + " Service paused");
            timer.Enabled = false;
        }

        protected override void OnContinue()
        {
            EventLog.WriteEntry(ServiceName + " Service continued");
            timer.Enabled = true;
        }



        private void ServiceTimer_Tick(object sender, System.Timers.ElapsedEventArgs e)
        {
	    this.timer.Stop();
	    SmtpClient client = new SmtpClient("smtp.gmail.com"); //pop.gmail.com  smtp.gmail.com
            client.EnableSsl = true;
            MailAddress from = new MailAddress("sundar@armaninfotech.com", "[ Your full name here]");
            MailAddress to = new MailAddress("shailesh@armaninfotech.com", "Your recepient name");
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
            message.Body = "This is a test For Checking the Windows Service........ ";
            message.Subject = "This is For Checking the Windows Service is Running in the Background..Test By sundar........ ";
            NetworkCredential myCreds = new NetworkCredential("sundar@armaninfotech.com", "sundar123", "");
            client.Credentials = myCreds;
            try
            {
                client.Send(message);
                //MessageBox.Show("Message Has Been Sent Successfully!");
            }
            catch (Exception ex)
            {
                // Console.WriteLine("Exception is:" + ex.ToString());
                //MessageBox.Show("Exception is:" + ex.ToString());
            } 
   
            this.timer.Start();         

        
        }
    }
}
  
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
11/15/2008 4:18:31 AM
thanks , its Really working fine ...........tell me what i did the mistake in this.................
0
Sundar123
11/15/2008 6:27:32 AM

 you didn't declare timer tick event in the constructor so that event is not firing,

you didn't set timer interval in the constructor

in that timer tick event , you have to stop the timer , then execute your code and again you have to start the timer.


Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
0
ramireddyindia
11/15/2008 6:31:43 AM
Reply:

Similar Artilces:

Run an .exe file from .NET application
Hi,  I've downloaded an MS log parser to parse the IIS log file. Now, my issue is that how do I convert the logparser.exe file as a batch file and make it run every one hour (or any other specific interval)? Or, is there any other way to call an .exe file from my .NET application?  Hope I am clear. Thanks in advance Sangeetha Add it to Task Scheduler as a scheduled task. You can call any .exe files using this code.    using System.Diagnostics; Process NewProcess = new Process(); string FilePath = "C:\\XPTO\\Something.exe" NewProc...

run window forms application (exe file) on web
hi i want to run a window froms exe application on web but i havn't any idea . so plz help me Hi there, If you mean that you want to Run your Application as a Service, then check out this link! Hope thats gonna help Best regards, Cute Best regards,~*Cute*~ You can't. All that would possibly happen is that the exe runs on the web server, and most server administrators frown on something like that. If you want to include WinForms in a web page, take a look at this:  http://aspnet.4guysfromrolla.com/articles/052604-1.aspx http://samples.gotdotnet.com/quickstart/winforms/do...

Running .exe file from a web application
Hi, I'm trying to run an .exe from my web application ans was wondering what the best way to do this was. I'd be grateful for any suggestions. Regards M EXE on the server, or on the client?  If it's on the client, then you're out of luck.  Security prevents it, unless the user's got their browser wide-open.  On the server, it's likely permissions problems.  Make sure that the ASPNET users has permission to execute the program. I'm trying to do the same thing (server-side). I'm trying to run an app I wrote in VB that starts a macro in another application. The w...

how to run a .exe file in a web application
Hi EveryOne, I hav a .dll and a .exe file placed in my bin folder of a web application now i hav to write code for running this .exe from the web application from code behind in c#.net so wat i hav to n how i hav to plz can any one help me doing with this work, im unable to go any further, any help would me mostly appreciated, thanx in advanceRatnakar Choudry,c.ratnakar@gmail.com,Tension Nahi Leneka Apun Hai Nah... Check below blog post Run executable files in c# HCHaissam Abdul MalakMCAD.NET| Blog | Hi, Try the following using System.Diagnostics; public partial class DropDownLis...

Can powerbuilder .NET Web Form Application run on Win2003 ?
Hello~~ I am testing powerbuilder11 TCP now. I followed the instruction on PDF file, and found I can successfully migrate my pbl to .net with IIS on Win2000 , and run it on browser; while I cannot successfully complete the same process with IIS on Win2003, I cannot run it on browser, various error messages shown on browser.... I guess there is further restriction for ASPNET on Win2003. Does anyone have good suggestion? Regards Alex Alex; Try the PB 11 Beta News Group .. we are not allowed to answer your PB 11 questions ...

Can powerbuilder .NET Web Form Application run on Win2003 ?
Hello~~ I am testing powerbuilder11 TCP now. I followed the instruction on PDF file, and found I can successfully migrate my pbl to .net with IIS on Win2000 , and run it on browser; while I cannot successfully complete the same process with IIS on Win2003, I cannot run it on browser, various error messages shown on browser.... I guess there is further restriction for ASPNET on Win2003. Does anyone have good suggestion? Regards Alex Alex; 1) Please do not cross-post. 2) Please use the PB 11 Beta News Group. Thanks .. Chris...

cant run application from .exe file
I am using PB6 with Sybase SQL Anywhere as my database server. My Operating System is Windows 98. My application runs via the Run button on the PowerBar, but when I created an .exe file it does not run from the start menu or desktop. I have checked the SQL Anywhere ODBC configuration, the database startup path, the start command, and have tried rebuilding the .exe to know avail. When I try to run the application from the .exe, I get the message: "DBMS is not supported in your current installation." Any suggestions will be appreciated. Rob The problem is either you...

run an .exe file from vb.net
I am trying to run notepad.exe from vb.net just to test, but it doesn't work. I want to be able to use this to run a DTS pkg exe file from vb.net. Any clues?  The code is the following: Imports System Imports System.Diagnostics Imports System.Runtime.InteropServices Public Class WebForm1 Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim program As New Process program.StartInfo.FileName = "c:\windows\system32\Notepad.exe" program.StartInfo.Arguments =...

Using .net AJAX enabled application in non .net Web Application
Hi,Does anyone have similar experience in development?  I want to check if it's possible to run .net ajax object (from one standalone .net framework platform in company) with non .net application (i.e. J2EE web application)?  It is because we want to add certain feature (i.e. office communicator chat) to our exist application (oracle J2ee). Please give me some advice :) Thanks! Hi, .Net AJAX is based on .Net Framework architecture. Thus .Net Framework currently lacks support for other platforms, such as Java. Please check this link: http://www.csharphelp.com/arch...

How to extract xml file from window application to web application in .net
hi..i have two software solutions both in .net one is desktop and another is web application.And i want to transfer data between these application using xml. In desktop solution i have created a xml schema and create a xml document that conforms to that schema.XML doucment is created which contains the data.Now i have to extract this xml document into my web application and store the data of this xml file into my database and vice versa. So tell me what are the different methods to get the document from desktop to web and from web to desktop.Actaully i am not much aware of this type i...

can a web application be converted as a exe file????
hi all can a web application be converted into a .exe file? or it can be only accessed through a network?? can anyone help me?? cheers bel..Thanks,Bel.. Hi,well not really but you can host it on a cd for example for easy standalone distribution. Take a look at this article: ASP. NET Client-side Hosting with Cassini.Grz, Kris. Read my blog. Handy Firefox plugins for web developers.Workaround for non working Mark as answer buttons....

Error when running exe file,but not in VS.NET
I have an application which produces an exception error when run outside VS.NET. But when the application is runned in release or debug mode,the exception error never occurs.Anyone encountered such a strange problem before? Hi, can you post what is the exception you are getting thanks.regards,Harishhttp://geekswithblogs.net/ranganh...

Can a .NET web based intranet application call a windows based .NET application?
   Is it possibly to have an asp.net 2.0 application call/invoke a windows desktop application written in .NET 2.0? We have a .NET 1.0 windows desktop application that was written in C#. We also have a new .NET intranet web application written in asp.net 2.0. Is it possibly to have a button on the web application that when pressed will invoke the .NET 1.0 windows application? And then if someone closes the application, it will return control back to the ASP.NET 2.0 application?    Are you referring to running a WinForms application on the server or on the client PC? ...

How can I run a .aspx file from .vb file in visual studio.net ?
Hello,     I want to make a Vb.net program which can run an .aspx file whenever a new flash file is put into the directory.  I already finish the IO.FileSystemWatcher part.  But when I detect a new file is put into the folder, how can I activate a .aspx program from vb.net . Robert Chu...

Web resources about - How to Run my .exe file or Application in the Background using .NET Application like explorer.exe file is Running always in the Background...(you can see in task Manager..) - asp.net.web-forms

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Miller accused's bail application adjourned until Friday
One of the two men charged with causing the one-punch death of Brisbane teenager Cole Miller will stay behind bars until at least Friday.

AVO application against Labor's Jamie Clements withdrawn
An application for an apprehended violence order against Labor powerbroker Jamie Clements - based on allegations he tried to kiss a female staffer ...

Apple Stores planned for India as application is filed with regulators
... India Times , the company has recently taken a major step in accomplishing that goal. According to the report, Apple has just filed an application ...

Seagate Introduces First 8 TB Hard Disk Drive for Consumer NAS Applications
Seagate Technology on Tuesday introduced its new breed of hard disk drives (HDDs) for network area storage (NAS) and RAID applications. The new ...

MBA: Mortgage Applications Increased in Latest Weekly Survey, Purchase Applications up 17% YoY
From the MBA: Refinance Mortgage Applications Increase as Rates Fall in Latest MBA Weekly Survey Mortgage applications increased 9.0 percent ...

Mortgage applications rebound
Mortgage applications increased 21.3 percent on a seasonally adjusted basis, for the week ending January 8th, versus previous week,

SURPRISE! Mizzou Sees Application Drop After Days Of Protests, Illusory Klan Hoods, Poop Swastika
SURPRISE! Mizzou Sees Application Drop After Days Of Protests, Illusory Klan Hoods, Poop Swastika

In Application To Move To Los Angeles, Rams Shit All Over City Of St. Louis
... to relocate to the greater Los Angeles metropolitan area. The relocation would be effective for the 2016 NFL League Year.” The Rams’ full application ...

Seagate pushing non-PC storage for 2016 with focus on surveillance applications
... products for cloud computing, consumer electronics, surveillance and enterprise storage for 2016. Seagate expects surveillance-related applications ...

Resources last updated: 1/21/2016 4:18:37 PM