I am looking to get the method/action name from a task in C#. Specifically I am implementing a custom task scheduler, and would like to generate statistics on the duration a task runs, which I will then aggregate by the method running inside of the task. In the visual studio debugger you can access this and see the m_action private variable, as well as the debugger display annotation, displays it as Method={0}. Is there any way to get access to this from the Task itself?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Envorinment.StackTrace
from inside the task or directly called methods by it.You could inherit from Task to make this real easy... I'm just going to implement the first constructor here for the example:
After that...
More examples. Inherit from
Task<T>
:Handle anonymous methods:
Well, you could use reflection to get at the private
m_action
field, given aTask
variabletask
:Then get the
Name
of the method and theDeclaringType
:To get the fully qualified method (
type + "." + name
)...But, as soon as the task executes to completion,
m_action
isnull
. I'm not sure how this would apply with TaskFactory.StartNew...