Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created March 16, 2011 15:34
Show Gist options
  • Select an option

  • Save mgroves/872672 to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/872672 to your computer and use it in GitHub Desktop.
threading and unit testing
using System.Threading;
using PostSharp.Aspects;
namespace MonoStockPortfolio.Framework
{
public class OnWorkerThreadAttribute : MethodInterceptionAspect
{
public static IThreadingService ThreadingService;
public override void OnInvoke(MethodInterceptionArgs args)
{
if(ThreadingService == null) ThreadingService = new ThreadingService();
ThreadingService.QueueUserWorkItem(d => args.Invoke(args.Arguments));
}
}
public interface IThreadingService
{
void QueueUserWorkItem(WaitCallback func);
}
public class ThreadingService : IThreadingService
{
public void QueueUserWorkItem(WaitCallback waitCallback)
{
ThreadPool.QueueUserWorkItem(waitCallback);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment