Ninject.Extensions.Interception.DynamixProxy를 사용하여 인터셉터를 작성하여 메소드 완료 시간을 기록하려고합니다. 이 같은 단일 스레드 환경 무언가에다중 스레드 환경에서 Ninject 차단
작동 : 스톱워치가 호출간에 공유되기 때문에 이것은 그러나 작동하지 않을
public class TimingInterceptor : SimpleInterceptor
{
readonly Stopwatch _stopwatch = new Stopwatch();
private bool _isStarted;
protected override void BeforeInvoke(IInvocation invocation)
{
_stopwatch.Restart();
if (_isStarted) throw new Exception("resetting stopwatch for another invocation => false results");
_isStarted = true;
invocation.Proceed();
}
protected override void AfterInvoke(IInvocation invocation)
{
Debug.WriteLine(_stopwatch.Elapsed);
_isStarted = false;
}
}
멀티 스레드 시나리오에서. BeforeInvoke에서 AfterInvoke로 StopWatch의 인스턴스를 전달하여 호출간에 공유되지 않게하는 방법은 무엇입니까?