2007-05-16 20:28:23 +00:00
|
|
|
#region CPL License
|
|
|
|
/*
|
|
|
|
Nuclex Framework
|
2010-07-08 12:37:39 +00:00
|
|
|
Copyright (C) 2002-2010 Nuclex Development Labs
|
2007-05-16 20:28:23 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the IBM Common Public License as
|
|
|
|
published by the IBM Corporation; either version 1.0 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
IBM Common Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the IBM Common Public
|
|
|
|
License along with this library
|
|
|
|
*/
|
|
|
|
#endregion
|
2007-07-24 20:15:19 +00:00
|
|
|
|
2007-04-16 17:18:16 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2007-07-04 19:19:48 +00:00
|
|
|
using System.Threading;
|
2007-04-16 17:18:16 +00:00
|
|
|
|
2007-07-01 19:27:40 +00:00
|
|
|
namespace Nuclex.Support.Scheduling {
|
2007-07-04 19:19:48 +00:00
|
|
|
|
|
|
|
/// <summary>Operation that executes a method in a background thread</summary>
|
2007-07-05 20:02:02 +00:00
|
|
|
public class ThreadCallbackOperation : ThreadOperation {
|
2007-07-04 19:19:48 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2007-08-31 21:24:40 +00:00
|
|
|
/// Initializes a new threaded method operation that will call back a
|
|
|
|
/// parameterless method from the background thread.
|
2007-07-04 19:19:48 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="method">Method to be invoked in a background thread</param>
|
|
|
|
/// <remarks>
|
|
|
|
/// Uses a ThreadPool thread to execute the method in
|
|
|
|
/// </remarks>
|
2007-07-05 20:02:02 +00:00
|
|
|
public ThreadCallbackOperation(ThreadStart method)
|
2007-07-04 19:19:48 +00:00
|
|
|
: this(method, true) { }
|
|
|
|
|
|
|
|
/// <summary>
|
2007-08-31 21:24:40 +00:00
|
|
|
/// Initializes a new threaded method operation that will call back a
|
|
|
|
/// parameterless method from the background thread and use the
|
|
|
|
/// thread pool optionally.
|
2007-07-04 19:19:48 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="method">Method to be invoked in a background thread</param>
|
|
|
|
/// <param name="useThreadPool">Whether to use a ThreadPool thread</param>
|
|
|
|
/// <remarks>
|
|
|
|
/// If useThreadPool is false, a new thread will be created. This guarantees
|
|
|
|
/// that the method will be executed immediately but has an impact on
|
|
|
|
/// performance since the creation of new threads is not a cheap operation.
|
|
|
|
/// </remarks>
|
2007-07-05 20:02:02 +00:00
|
|
|
public ThreadCallbackOperation(ThreadStart method, bool useThreadPool)
|
|
|
|
: base(useThreadPool) {
|
2007-07-04 19:19:48 +00:00
|
|
|
|
2007-07-05 20:02:02 +00:00
|
|
|
this.method = method;
|
|
|
|
}
|
2007-07-04 19:19:48 +00:00
|
|
|
|
2007-07-05 20:02:02 +00:00
|
|
|
/// <summary>Executes the thread callback in the background thread</summary>
|
|
|
|
protected override void Execute() {
|
|
|
|
this.method();
|
2007-07-04 19:19:48 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 20:02:02 +00:00
|
|
|
/// <summary>Method to be invoked in a background thread</summary>
|
|
|
|
private ThreadStart method;
|
|
|
|
|
2007-04-16 17:18:16 +00:00
|
|
|
}
|
2007-07-04 19:19:48 +00:00
|
|
|
|
2007-07-01 19:27:40 +00:00
|
|
|
} // namespace Nuclex.Support.Scheduling
|