Created
March 16, 2011 15:34
-
-
Save mgroves/872672 to your computer and use it in GitHub Desktop.
threading and unit testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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