Link to home
Start Free TrialLog in
Avatar of techques
techques

asked on

How a web application C# code keeps on running a while loop for every minute?

Hi

I built a web application to send email at regular time. Now, I use a windows service to check whether there is new email needs to be sent for every minute. So, it has a web application for me to input email address, email content, datetime to send AND a windows service program to have a timer to check MSSQL regularly to send email.

Now, I want to combine them into one web or desktop application. How can the while loop in C# code can execute code for every minute?

Thanks for advice.
SOLUTION
Avatar of VegasCid
VegasCid

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Toms Edison
It is better to have a windows service to sent mail, because if you create a web application or windows application it requires that an user is logged in to the machine for this application to run but it is not the case in windows service.

What I would suggest is have a table where you have the mail ids of users to whom mail has to be sent. Change your web application to  update this table (add/remove mail ids) Your windows service should be checking this data at regular interval and sent mail.

Instead of windows service you can also create a console application that sents mail to the configured users. You can schedule this application to run in regular interval. This way you can avoid creating a windows service and the timer logics
Avatar of techques
techques

ASKER

I had existing windows service program to send email. However, it is inconvenient to distribute to users as it will take much support work. So, I want to combine the client interface with the windows service program. When the user execute the program, it will run.

using System.Timers; is it for desktop application?
how about web application? how can i do it ?
while (600000)  //for each minute
{
execute the mail code
}
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In code-Behind put your code in pageLoad section
A windows service cannot have user interface.
You can probably build a windows application for modifying email addresses and use the existing windows service for sending mails.

Because as I said if you are integrating mailing part with mail updating part into a windows application then an user has to be logged into the machine and make sure that the application is open so that it sends mail in regular interval