Kuttan Sujith
Kuttan Sujith

Reputation: 7979

Calling a function periodically c#

I am sending mails from my codes, for some activities.

But some mails may fail due to some or other reason.

I am keeping details of all such failed mails in a table.

Now my plan is to periodically check that table and resend mails if the table contain failed mails.

Or in other words,I want to call a method SentFailedMails() in every 12 hours.

How can I do this is c#

My application is a WCF service,Hosted on IIS

Upvotes: 0

Views: 645

Answers (3)

Augure
Augure

Reputation: 370

You can use a threading.timer and set it to 12:00:00 then give it your mail method to execute . Don't forget about the dispatcher to change thread though.

Upvotes: 0

tobsen
tobsen

Reputation: 5398

You might want to use a scheduler like Quartz.net

Upvotes: 1

Ppp
Ppp

Reputation: 1015

Create a very simple console application that do the task (move your SentFailedMails() method to this application and execute it on run).

Place the exe file for the console application in a folder of your server.

Use Windows Task Scheduler to schedule the exe file execution for every 12 hours or on any specific time.

Upvotes: 1

Related Questions