If an interviewer thinks there is a best answer to that question then you can be sure that the interviewer doesn't know what they are doing. At best they don't understand the interview process and at worst they are arrogant.
There are of course bad answers to that question - like "what is a class?"
I have crrated below windows service and installed it using InstallShield. I am able to see the windows service Started in the Control Panel-Services but I am not getting any email when the minutes turns to 30.
Can anyone help please...
publicpartialclass MyTestWindowsService : ServiceBase
eventLog1.Source = "MyEventLogSource";
eventLog1.Log = "MyNewLog Comes here!";
protectedoverridevoid OnStart(string args)
privatevoid timer1_Tick(object sender, EventArgs e)
if (DateTime.Now.Minute == 30)
eventLog1.WriteEntry("starting to send email.");
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("firstname.lastname@example.org");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("email@example.com", "mypassword");
SmtpServer.EnableSsl = true;
catch (Exception ex)
eventLog1.WriteEntry("failed sending email.");
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException
Which "same problem" are you talking about? I see several problem with this code.
Your service is started, OnStart is called, seeing that there is nothing in your OnStart method, nothing happens, the method exits, your service exits.
You do not have a timer 1 to use the tick event handler you have setup
You do not have a timer 2 to use the tick event handler you have setup
You would need to set the UseDefaultCredentials property to false
You probably don't have access to network resources depending on the user account your service is running under.
You can lead a developer to CodeProject, but you can't make them think.
The Theory of Gravity was invented for the sole purpose of distracting you from investigating the scientific fact that the Earth sucks.