Skip to content

Instantly share code, notes, and snippets.

@snmslavk
Created April 7, 2016 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snmslavk/87fa46088868f895dc17a372b75e0499 to your computer and use it in GitHub Desktop.
Save snmslavk/87fa46088868f895dc17a372b75e0499 to your computer and use it in GitHub Desktop.
Start banch of files every day at specific time
using System;
namespace RunFileLib
{
public class ExeFileModel
{
public ExeFileModel()
{
LastStart = DateTime.Now.AddDays(-1);
}
public string PathFile { get; set; }
public TimeSpan TimeExec { get; set; }
public DateTime LastStart { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Configuration;
namespace RunFileLib
{
public class MainLogic
{
public MainLogic()
{
FillDict();
}
private List<ExeFileModel> ListExeFileModel = new List<ExeFileModel>();
private void FillDict()
{
int i=1;
while (GetPath(i)!=null
&& GetTimeExec(i).HasValue)
{
ListExeFileModel.Add(new ExeFileModel()
{
PathFile = GetPath(i),
TimeExec = GetTimeExec(i).Value
});
i++;
}
}
public void RunFiles()
{
ListExeFileModel.ForEach(
x =>
{
if (DateTime.Now.TimeOfDay >= x.TimeExec
&& x.LastStart.Date < DateTime.Now.Date)
{
System.Diagnostics.Process.Start(x.PathFile);
x.LastStart = DateTime.Now;
}
}
);
}
private string GetPath(int i)
{
return ConfigurationManager.AppSettings["file_path" + i];
}
private TimeSpan? GetTimeExec(int i)
{
return ConfigurationManager.AppSettings["time_exec" + i]==null?
(TimeSpan?)null : TimeSpan.Parse(ConfigurationManager.AppSettings["time_exec" + i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment