Created
January 23, 2014 04:52
-
-
Save alanjuden/8573031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace Epc | |
{ | |
public class TestTaskHost : TaskHost | |
{ | |
public List<Task> Tasks { get; set; } | |
private System.Timers.Timer _timer = null; | |
private int _timerInvervalInSeconds = 30; | |
public TestTaskHost(int timerIntervalInSeconds = 30) | |
{ | |
this.Tasks = new List<Task>(); | |
_timerInvervalInSeconds = timerIntervalInSeconds; | |
} | |
public void Start() | |
{ | |
LogEvent(LogLevels.Service, "Service Starting..."); | |
_timer = new System.Timers.Timer(_timerInvervalInSeconds * 1000); | |
_timer.Elapsed += (s, e) => | |
{ | |
LogEvent(LogLevels.Debug, "In Timer Elapsed"); | |
this.Tasks.WithEach(x => x.Start(this)); | |
MemoryManagement.FlushMemory(); | |
LogEvent(LogLevels.Debug, "Out Timer Elapsed"); | |
}; | |
_timer.Enabled = true; | |
_timer.Start(); | |
System.Threading.Thread.Sleep(3000); | |
while (this.Tasks.Any(x => x.IsBusy)) | |
{ | |
System.Threading.Thread.Sleep(1000); | |
} | |
} | |
private void LogEvent(LogLevels logLevel, string text) | |
{ | |
Console.WriteLine(String.Format("[{0}] {1} - {2}", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss.fff"), "[Task] TestTaskHost", text)); | |
} | |
#region TaskHost Members | |
public bool IsClosing { get; set; } | |
public bool ForceRun | |
{ | |
get | |
{ | |
return true; | |
} | |
} | |
public void LogEvent(Task task, LogLevels logLevel, string text) | |
{ | |
Console.WriteLine(String.Format("[{0}] {1} - {2}", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss.fff"), "[Task] " + task.TaskName, text)); | |
} | |
public void LogException(Task task, Exception ex) | |
{ | |
Console.WriteLine(String.Format("[{0}] {1} - {2}", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss.fff"), "[Task] " + task.TaskName, ex.ExceptionToString())); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment