Normal
I've been working on a new job dispatcher/scheduler for MP that may be of interest to you...As the low down on how its implemented:scheduler runs in its own threaduse a priority queuethread safeuses .NET thread pool for worker threadsbased on ideas presented by .NET 2's BackgroundWorker objectreports correct stack for worker thread exceptionsCurrently it is working very well and is very easy to work with, the major limitation right now is that it doesn't persist the outstanding jobs, something that it needs to be truly useful and suitable for use in a service.Examples of how to schedule a job:[code] Job job = new Job(); job.DoWork += new DoWorkEventHandler(RefreshWeather); job.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RefreshWeatherCompleted); job.Name = "RefreshWeather"; job.Argument = "JAXX0085"; job.Dispatch(); ... ...[/code]The work handler:[code] static void RefreshWeather(object sender, DoWorkEventArgs e) { using(WeatherReader reader = new WeatherReader((string)e.Argument)) e.Result = reader.Read(); }[/code]The completion handler:[code] static void RefreshWeatherCompleted(object sender, RunWorkerCompletedEventArgs e) { try { foreach(WeatherForecast weather in (WeatherCollection)e.Result) { Console.WriteLine(" Location: {0}", weather.Location.Name); Console.WriteLine(" Time: {0}", weather.Location.Time); Console.WriteLine(" Day: {0}", weather.Day); Console.WriteLine(" Latitude: {0}", weather.Location.Latitude); Console.WriteLine("Longtitude: {0}", weather.Location.Longtitude); Console.WriteLine(" Sunrise: {0}", weather.Location.Sunrise); Console.WriteLine(" Sunset: {0}", weather.Location.Sunset); } } catch(Exception exception) { Console.WriteLine("Application.RefreshWeatherCompleted: {0}", exception.Message); } // re-schedule for 30 minutes time ((Job)sender).Dispatch(TimeSpan.FromMinutes(30)); }[/code]I'm happy to zip up the code and the test app if you would like to play around with this, once persistance has been implemented I will be presenting this to the other team members in the hope that it will be used as the defacto sheduler in MP.At some point in the future I hope to to add ISynchronizeInvoke support for the controls used in MP to simplify manipulating UI elements from within the worker threads.The Dispatch method allows you to work with absolute and relative times.If it is to be used in the project then I'll also be adding support for waking the computer from standby.Cheers,Smirnoff.
I've been working on a new job dispatcher/scheduler for MP that may be of interest to you...
As the low down on how its implemented:
Currently it is working very well and is very easy to work with, the major limitation right now is that it doesn't persist the outstanding jobs, something that it needs to be truly useful and suitable for use in a service.
Examples of how to schedule a job:
[code]
Job job = new Job();
job.DoWork += new DoWorkEventHandler(RefreshWeather);
job.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RefreshWeatherCompleted);
job.Name = "RefreshWeather";
job.Argument = "JAXX0085";
job.Dispatch();
...
[/code]
The work handler:
static void RefreshWeather(object sender, DoWorkEventArgs e)
{
using(WeatherReader reader = new WeatherReader((string)e.Argument))
e.Result = reader.Read();
}
The completion handler:
static void RefreshWeatherCompleted(object sender, RunWorkerCompletedEventArgs e)
try
foreach(WeatherForecast weather in (WeatherCollection)e.Result)
Console.WriteLine(" Location: {0}", weather.Location.Name);
Console.WriteLine(" Time: {0}", weather.Location.Time);
Console.WriteLine(" Day: {0}", weather.Day);
Console.WriteLine(" Latitude: {0}", weather.Location.Latitude);
Console.WriteLine("Longtitude: {0}", weather.Location.Longtitude);
Console.WriteLine(" Sunrise: {0}", weather.Location.Sunrise);
Console.WriteLine(" Sunset: {0}", weather.Location.Sunset);
catch(Exception exception)
Console.WriteLine("Application.RefreshWeatherCompleted: {0}", exception.Message);
// re-schedule for 30 minutes time
((Job)sender).Dispatch(TimeSpan.FromMinutes(30));
I'm happy to zip up the code and the test app if you would like to play around with this, once persistance has been implemented I will be presenting this to the other team members in the hope that it will be used as the defacto sheduler in MP.
At some point in the future I hope to to add ISynchronizeInvoke support for the controls used in MP to simplify manipulating UI elements from within the worker threads.
The Dispatch method allows you to work with absolute and relative times.
If it is to be used in the project then I'll also be adding support for waking the computer from standby.
Cheers,
Smirnoff.