Parallel.NET - Background Task Scheduler

Last Update
12 June 2013
Regular License
$9
Extended License
$45
Sales
30

The Parallel.NET component provides you with a simple and robust way of getting your .NET applications to perform regular tasks at configurable intervals. There is no interference to other aspects of the application including the UI or users.

What are the features?

Execute tasks at configurable intervals Run multiple tasks at different intervals using 1 ParallelScheduler Configure whether background tasks use the ThreadPool or run on their own thread Specify whether the task should run infinitely or for a specified number of times Add observers for any background task having the observers alerted each time the task runs Allow the observers to manipulate the output from the task that was run Specify how the observers will execute – Sequential or Concurrently Exception handling just in case a task does not consume its own exceptions

When would I use this?

Loading news feeds Clean-up operations Sending emails without reducing the responsiveness of the UI Monitoring internal and external resources Updating devices or other services with new information Refresh your data sources from external/internal web services Monitor database tables for changes or new information Monitor inboxes for new emails Process video, images, and other multimedia files Send large files

Tasks that take a long time including tasks that are processor intensive, hard disk intensive or task that access external resources such as Web/WCF services, databases (in some cases), news feeds, etc. can be run in the background. Once these tasks are completed the observers will be notified and then they can perform their work which can include updating the UI, notifying users of changes & updates, etc.

Technologies

This component is built using the .NET 2.0 Framework which means in can be used in all .NET applications that are using the 2.0 framework or newer. This includes .NET 2.0, 3.0, 3.5, 4.0, & 4.5+. This component can be used all types of .NET applications including:

Console Windows Forms WPF ASP.NET WebForms ASP.NET MVC Windows Services Web Services (XML/WCF) Silverlight

You can immediately use this within your application and is very simple.

Is it reliable?

The component also ensures that many pitfalls are not encountered including:

No Deadlocks No Memory leaks – clean up through the dispose method & consider problems such as the lapsed listener No Exceptions leaks – Exception handling through to ensure undesired termination of the application does not occur ASP.NET ThreadPool & Service Unavailable – Gives control of whether ThreadPool threads are used (by default no). This ensures that threads are not taken away from high availability ASP.NET applications causing the dreaded “Service Unavailable” message Task/Background work structure – Flexible mechanism for creating complex background operations Strong name signed – Allows referencing in other application that are strong named signed & also installed into the GAC

What is in the package?

.NET 2.0 Assemblies Debug files (PDB) Xml comments (Intellisense) Usage documentation API Documentation 2 x Console demo application ASP.NET MVC demo application ASP.NET Webforms demo application WinForm demo application C# Source Code Visual Studio 2010 SP1 & 2012 Solution

Support

Ask any questions or suggest features at support.avantprime.com!

How would I use this component?

Example of how to use the ParallelScheduler in conjunction with the UrlReaderBackgroundWork to infinitely poll a URL every 5 seconds. The work is scheduled to start immediately using ThreadPool threads with two registered observers that will be executed in Parallel every time the work is done.

using System; using System.Collections.Generic; using System.Threading;

namespace AvantPrime.ParallelNET.TestConsole { class Program { static void Main(string[] args) { if (args.Length > 0) { // Create the background work to be performed // by the scheduler. var url = args[0]; var urlReader = new UrlReaderBackgroundWork(url) { UseThreadPool = true, StartImmediately = true, RepeatTimes = (int)WorkRecurrence.Infinite, Interval = TimeSpan.FromSeconds(5), Observers = new List<Action<object>> { ObserverA, ObserverB }, ObserverExecutionMethod = ExecutionMethod.Parallel };

Console.WriteLine("Application started at: {0}\n", DateTime.Now);

// Create and configure the background scheduler. // Wrap the scheduler inside a using block to automtically // dispose of it when done. Alternately simply call the // Stop and/or Dispose operations to perform the same // work, for example, if the scheduler is terminated at // another location. using (var scheduler = new ParallelScheduler(urlReader)) { // Start the scheduler. scheduler.Start();

// Pause the application to demonstrate that // the background task is working as expected. // We stop at this point before the scheduler // gets cleaned up. Console.WriteLine("Application is currently performing background tasks with Concurrently executing observers...\n"); Console.ReadKey(); }

Console.WriteLine("\nPress any key to terminate application..."); Console.ReadKey(); } else { Console.WriteLine("No parameters supplied"); Console.ReadKey(); } }

public static void ObserverA(object data) { Console.WriteLine("Observer A called at: {0}. Thread ID: {1}.", DateTime.Now, Thread.CurrentThread.ManagedThreadId); }

public static void ObserverB(object data) { Console.WriteLine("Observer B called at: {0}. Thread ID: {1}.\n", DateTime.Now, Thread.CurrentThread.ManagedThreadId); } } }