static void Start() { if (File.Exists("sys.set") == true) { ReadFile(); if (stoper.FinalTime >= DateTime.Now) { timer = new System.Threading.Timer(TimerCallbackFunc, null, 0, 60000); } else if (stoper.FinalTime.Day < DateTime.Now.Day) { stoper.FinalTime = DateTime.Now + stoper.TimeSpan; SaveFile(); } else { PCShutdown(); } } else { // Push app to register here stoper = new Stoper() { Password = "", Login = "", TimeSpan = TimeSpan.FromMilliseconds(0), FinalTime = DateTime.Parse("1/1/0") }; SaveFile(); } }
static void ReadFile() { using (FileStream fs = new FileStream("sys.set", FileMode.OpenOrCreate, FileAccess.Read)) { BinaryFormatter bf = new BinaryFormatter(); stoper = (Stoper)bf.Deserialize(fs); } }