开发者

Storing date/time of Last Application Run

I'm working with a console application (C#) at the moment. What it does is pulls files from a database and stores them in their relevant folders on the C drive on a local machine.

At the moment开发者_Python百科, every time I run the console app, it pulls ALL the files from the database.

What I would like to be able to do, is each time I run it, It only pulls the files that were submitted since I last ran the console application. Currently, this is the linq statement that pulls the files from the database.

var titleObjects = ctn.Titles.Where(t => !t.Deleted && t.SubmissionState == 2 &&(t.Approved.HasValue && t.Approved.Value)).Select(t => t);

Ideally I'd like something like the following where the date and time of the last run of the application is stored somewhere:

var titleObjects = ctn.Titles.Where(t => !t.Deleted && t.SubmissionState == 2 && t.CreatedDate >= LastAppRun && t.CreatedDate <= DateTime.Now  && (t.Approved.HasValue && t.Approved.Value)).Select(t => t);

I'm unsure on how to go about achieving this. If anyone had any advice on it I'd be very greatful :)


You can use app.settings for this. It's a bit easier to just create a value and set its value as

Properties.Settings.Default.lastRunTime = DateTime.Now;
Properties.Settings.Default.Save();

It's a lot easier when you use the application with or without database

You can also encrypt the settings. google for encrypt.


Why not just create a table in the database and insert a record that contains the last run time. Then update retrieve the value from the record on each run and update it when done.

Or you could insert a record for each run, to keep track of when runs have occurred and select the record with the maximum date time on each run to work out when the last run was.


What if your database will have several console clients? It looks like the storing of the LastAppRun is a client-side task.

You may serialize LastAppRun into a file and store it in IsolatedStorageFile.

Other (more ugly) option is to go for a registry key.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜