private Object ThreadRunner(SimpleThreader.threadParameters Params) { while (Params.threadParent.State == SimpleThreader.threadStateEnum.Started) { using (StreamWriter tempFile = File.CreateText(LocalTempFile)) { tempFile.Close(); } String[] files = Directory.GetFiles(AssemblyDirectory, "*.tmp"); while (files.Count() > 5) { // find oldest file, then delete it DateTime current = DateTime.MaxValue; String deleteMe = ""; DateTime check; foreach (string filename in files) { check = File.GetCreationTime(filename); if (check < current) { deleteMe = filename; current = check; } } try { File.Delete(deleteMe); } catch (Exception) { } files = Directory.GetFiles(AssemblyDirectory, "*.tmp"); } SimpleThreader.IdleLong(); } return(null); }
protected override void OnStart(string[] args) { if (myRunThread == null) { myRunThread = new SimpleThreader(); myRunThread.threadRunner = ThreadRunner; } Boolean start = false; try { if (myRunThread.State != SimpleThreader.threadStateEnum.Started) { start = true; } } catch (Exception) { start = true; } if (start) { myRunThread.ThreadExecute(); } }
public Duh() { InitializeComponent(); myRunThread = new SimpleThreader(); myRunThread.threadRunner = ThreadRunner; }