I have a circumstance where I have enqueued a number of Action
objects and I have a threadpool working through each Action
. However, if the application shuts down before the queue is empty, I would like to log what is remaining in the queue before closing.
Is it possible to get the method body from an Action
object? I can see the MethodBody
object from Action.Method.GetMethodBody()
, but I don't see a way to get this out as a string.
Any thoughts, or am I crazy?
EDIT: One more thing; I would like to retain state information as well. That is, I would like to also retain the values of any variables used within the Action
.
Yes, you're crazy.
The code being executed has been compiled down to IL, and then JIT compiled to machine code. The text of the action is long gone.
You need to not be queuing Action. Instead, create a structure which contains the Action and the method name, and any other information you want to have logged. Make a queue of those instead of Action.