Click here to Skip to main content
15,901,368 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have implemented a console application that sends a mail based on the data returned from a web service. I have configured it as a windows task scheduler that runs every 5 mints.

Here I am retrieving a list of employee status using the service. Employee status can be Active, Inactive and few others too. I have to send a notification mail to the employee email id whenever the following status change occurs, "Active-> Inactive" and "Inactive->Active". So in short this requires me to store the previous status.

Is there any way to store the previous data.. Kindly advice.

Thanks

What I have tried:

I tried using static variable. But I believe since the application is run each 5 mints, it starts as a new application
Posted
Updated 23-Jan-18 3:45am

If the task runs as new each time then any memory variables used in the previous run do not exist. You need to use permanent storage, i.e. a disk file. Alternatively you could have a single instance of the application that uses a timer to run every five minutes. In that way you could keep all the information in memory.
 
Share this answer
 
Comments
Divya B Nair 23-Jan-18 15:53pm    
In this case, we can configure the task in the scheduler to start only once which then internally calls timer with 5 mints each. Right?
Richard MacCutchan 24-Jan-18 3:29am    
Yes, exactly right. I am not sure how to implement a Windows timer in a console application, but it should be possible.
I agree with Richard: if this is a new app firing every few minutes, then you will need permanent storage outside the app - but I'd suggest that a Database might be better than a disk file, as they are better organised and require less "thinking about" when it comes to adding, removing, or changing data.
Have a look here: Walkthrough: Saving Data to a Database (Single Table)[^] it's not that complicated when you get your head round it, and it's stuff that it's well worth knowing!
 
Share this answer
 
Comments
Divya B Nair 23-Jan-18 15:55pm    
I am used to working with database but we don't prefer to use db just to store this information. That would be our last option :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900