Y
Yahoo
I have a programming issue where I need to know the whole history of the
call stack to ensure it was never within a given method (specifically my own
method). I am hooking into the XmlDocument nodechanged event, I need to from
this event call modify a different node in this xmldocument, thus without
somekind of check we will be off in an infinite loop. Currently I am using
the System.Diagnostics classes but feel its not right to use these classes
like this. I would expect a master call stack to be kepted in the threading
class (or even reflections) but i dont see it. Is there a better way?
private bool IsFromUs()
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame;
MethodBase stackFrameMethod;
string typeName;
//find the first system.xml method, this always exists
int position=0;
for(int x = position; x<stackTrace.FrameCount; x++)
{
stackFrame = stackTrace.GetFrame(x);
stackFrameMethod = stackFrame.GetMethod();
typeName = stackFrameMethod.ReflectedType.FullName;
if (typeName.StartsWith("System.Xml"))
{
position = x;
break;
}
}
//now determine if we were the cause of this notification
for(int x = position; x<stackTrace.FrameCount; x++)
{
stackFrame = stackTrace.GetFrame(x);
stackFrameMethod = stackFrame.GetMethod();
typeName = stackFrameMethod.ReflectedType.FullName;
if (typeName.StartsWith("RuleEngine"))
return true;
}
return false;
}
call stack to ensure it was never within a given method (specifically my own
method). I am hooking into the XmlDocument nodechanged event, I need to from
this event call modify a different node in this xmldocument, thus without
somekind of check we will be off in an infinite loop. Currently I am using
the System.Diagnostics classes but feel its not right to use these classes
like this. I would expect a master call stack to be kepted in the threading
class (or even reflections) but i dont see it. Is there a better way?
private bool IsFromUs()
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame;
MethodBase stackFrameMethod;
string typeName;
//find the first system.xml method, this always exists
int position=0;
for(int x = position; x<stackTrace.FrameCount; x++)
{
stackFrame = stackTrace.GetFrame(x);
stackFrameMethod = stackFrame.GetMethod();
typeName = stackFrameMethod.ReflectedType.FullName;
if (typeName.StartsWith("System.Xml"))
{
position = x;
break;
}
}
//now determine if we were the cause of this notification
for(int x = position; x<stackTrace.FrameCount; x++)
{
stackFrame = stackTrace.GetFrame(x);
stackFrameMethod = stackFrame.GetMethod();
typeName = stackFrameMethod.ReflectedType.FullName;
if (typeName.StartsWith("RuleEngine"))
return true;
}
return false;
}