home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Scheduler in MP ? (for a plugin)
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Smirnuff" data-source="post: 18888" data-attributes="member: 10545"><p>I've been working on a new job dispatcher/scheduler for MP that may be of interest to you...</p><p></p><p>As the low down on how its implemented:</p><p></p><ul> <li data-xf-list-type="ul">scheduler runs in its own thread<br /> use a priority queue<br /> thread safe<br /> uses .NET thread pool for worker threads<br /> based on ideas presented by .NET 2's BackgroundWorker object<br /> reports correct stack for worker thread exceptions</li> </ul><p></p><p>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.</p><p></p><p>Examples of how to schedule a job:</p><p></p><p>[code]</p><p></p><p> Job job = new Job();</p><p></p><p> job.DoWork += new DoWorkEventHandler(RefreshWeather);</p><p> job.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RefreshWeatherCompleted);</p><p> job.Name = "RefreshWeather";</p><p> job.Argument = "JAXX0085";</p><p> job.Dispatch();</p><p></p><p> ...</p><p> ...</p><p>[/code]</p><p></p><p>The work handler:</p><p></p><p>[code]</p><p> static void RefreshWeather(object sender, DoWorkEventArgs e)</p><p> {</p><p> using(WeatherReader reader = new WeatherReader((string)e.Argument))</p><p> e.Result = reader.Read(); </p><p> }</p><p>[/code]</p><p></p><p>The completion handler:</p><p></p><p>[code]</p><p> static void RefreshWeatherCompleted(object sender, RunWorkerCompletedEventArgs e)</p><p> {</p><p> try</p><p> {</p><p> foreach(WeatherForecast weather in (WeatherCollection)e.Result)</p><p> {</p><p> Console.WriteLine(" Location: {0}", weather.Location.Name);</p><p> Console.WriteLine(" Time: {0}", weather.Location.Time);</p><p> Console.WriteLine(" Day: {0}", weather.Day);</p><p> Console.WriteLine(" Latitude: {0}", weather.Location.Latitude);</p><p> Console.WriteLine("Longtitude: {0}", weather.Location.Longtitude);</p><p> Console.WriteLine(" Sunrise: {0}", weather.Location.Sunrise);</p><p> Console.WriteLine(" Sunset: {0}", weather.Location.Sunset);</p><p> }</p><p> }</p><p> catch(Exception exception)</p><p> {</p><p> Console.WriteLine("Application.RefreshWeatherCompleted: {0}", exception.Message);</p><p> }</p><p></p><p></p><p> // re-schedule for 30 minutes time </p><p> ((Job)sender).Dispatch(TimeSpan.FromMinutes(30));</p><p> }</p><p>[/code]</p><p></p><p>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.</p><p></p><p>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.</p><p></p><p>The Dispatch method allows you to work with absolute and relative times.</p><p></p><p>If it is to be used in the project then I'll also be adding support for waking the computer from standby.</p><p></p><p>Cheers,</p><p>Smirnoff.</p></blockquote><p></p>
[QUOTE="Smirnuff, post: 18888, member: 10545"] 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: [list]scheduler runs in its own thread use a priority queue thread safe uses .NET thread pool for worker threads based on ideas presented by .NET 2's BackgroundWorker object reports correct stack for worker thread exceptions[/list] 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: [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. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Scheduler in MP ? (for a plugin)
Contact us
RSS
Top
Bottom