##// END OF EJS Templates
Code review for RunnableComponent...
Code review for RunnableComponent Added StaApartment class based on System.Windows.Forms.Application message loop

File last commit:

r200:71e543dbe65a v2
r210:5dc21f6a3222 v2
Show More
TraceContext.cs
82 lines | 2.9 KiB | text/x-csharp | CSharpLexer
cin
rewritten tracing
r92 using System;
using System.Collections.Generic;
using System.Threading;
namespace Implab.Diagnostics {
/// <summary>
/// Trace context is bound to the specific thread, each thread has it's own ThreadContext.
/// </summary>
/// <remarks>
/// ThreadContext manages relations between logical operations and threads.
/// </remarks>
public class TraceContext {
[ThreadStatic]
static TraceContext _instance;
OperationContext m_current = OperationContext.EMPTY;
readonly Stack<OperationContext> m_stack = new Stack<OperationContext>();
readonly int m_threadId;
public static TraceContext Instance {
get {
if (_instance == null)
_instance = new TraceContext();
return _instance;
}
}
public TraceContext() {
m_threadId = Thread.CurrentThread.ManagedThreadId;
}
public int ThreadId {
get { return m_threadId; }
}
public LogicalOperation CurrentOperation {
get {
return m_current.CurrentOperation;
}
}
public void EnterLogicalOperation(LogicalOperation operation, bool takeOwnership) {
cin
sync
r133 //var prev = CurrentOperation;
cin
Improved logging
r134 //LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(takeOwnership ? TraceEventType.Attach : TraceEventType.Enter, String.Format("{0} -> {1}",prev.Name, operation.Name)));
cin
rewritten tracing
r92 m_stack.Push(m_current);
m_current = new OperationContext(operation, takeOwnership);
}
public void StartLogicalOperation(string name) {
cin
working version of the project
r200 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceContext.Instance.CurrentOperation, TraceEventType.OperationStarted, name));
cin
rewritten tracing
r92 m_current.BeginLogicalOperation(name);
}
public void StartLogicalOperation() {
cin
improved tracing...
r93 StartLogicalOperation(String.Empty);
cin
rewritten tracing
r92 }
cin
minor changes
r195 public LogicalOperation EndLogicalOperation() {
return m_current.EndLogicalOperation();
cin
rewritten tracing
r92 }
public LogicalOperation DetachLogicalOperation() {
cin
minor fixes
r94 var prev = m_current.DetachLogicalOperation();
cin
sync
r133 //LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format("{0} -> {1}",prev.Name, CurrentOperation.Name)));
cin
minor fixes
r94 return prev;
cin
rewritten tracing
r92 }
public void Leave() {
cin
improved tracing...
r93 if (m_stack.Count > 0) {
m_current.Leave();
cin
sync
r133 //var prev = CurrentOperation;
cin
rewritten tracing
r92 m_current = m_stack.Pop();
cin
sync
r133 //LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Leave, String.Format("{0} -> {1}", prev.Name, CurrentOperation.Name)));
cin
improved tracing...
r93 } else {
cin
Promises rewritten, added improved version of AsyncQueue
r119 TraceLog.TraceWarning("Attempt to leave the last operation context");
cin
rewritten tracing
r92 m_current = OperationContext.EMPTY;
}
}
}
}