using System; using System.Collections.Generic; using System.Linq; using System.Text; using Castle.Core.Interceptor; using System.Threading; using PresentationModelBase; using System.ComponentModel; namespace App.Configuration { class BackgroundWorkInterceptor : IInterceptor { #region IInterceptor Members public void Intercept(IInvocation invocation) { if (!CheckIfShouldIntercept(invocation)) { invocation.Proceed(); return; } PresentationModel pm = (PresentationModel)invocation.InvocationTarget; ThreadPool.QueueUserWorkItem( o => { SetIsWorkingProperty(pm, true); invocation.Proceed(); SetIsWorkingProperty(pm, false); }); } #endregion void SetIsWorkingProperty(PresentationModel pm, bool value) { var property = TypeDescriptor.GetProperties(typeof(PresentationModel)).Find("IsWorking", false); property.SetValue(pm, value); } bool CheckIfShouldIntercept(IInvocation invocation) { if (invocation.Method.Name == "InvokeMethod") return true; return false; } } }
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Skills that self-taught computer programmers lack