mirror of
https://github.com/mgroves/MonodroidStockPortfolio.git
synced 2024-12-28 03:00:17 +00:00
31 lines
No EOL
996 B
C#
31 lines
No EOL
996 B
C#
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));
|
|
}
|
|
}
|
|
|
|
// this is kinda fail, but it helps with testing to inject in a "non threaded" service
|
|
// and I suppose it might make refactoring easier maybe...? just go with it
|
|
public interface IThreadingService
|
|
{
|
|
void QueueUserWorkItem(WaitCallback func);
|
|
}
|
|
|
|
public class ThreadingService : IThreadingService
|
|
{
|
|
public void QueueUserWorkItem(WaitCallback waitCallback)
|
|
{
|
|
ThreadPool.QueueUserWorkItem(waitCallback);
|
|
}
|
|
}
|
|
} |