C#-如何为调用者创建堆栈Id?

C#-如何为调用者创建堆栈Id?,c#,task,callstack,C#,Task,Callstack,我想为方法调用生成调用方Id,这是什么?CallerID是调用Task.CurrentId之类的方法的标识,但在这种情况下,我不想创建新线程来访问ThreadId, 例如: public class OperationMethodContext { public static OperationMethodContext Current { get; set; } public int Id { get; set; } public string MethodN

我想为方法调用生成调用方Id,这是什么?CallerID是调用Task.CurrentId之类的方法的标识,但在这种情况下,我不想创建新线程来访问ThreadId, 例如:

    public class OperationMethodContext
{
    public static OperationMethodContext Current { get; set; }

    public int Id { get; set; }
    public string MethodName { get; set; }
    public Guid Guid { get; set; }
}

internal class Program
{
    private static void Main(string[] args)
    {
        OperationMethodContext.Current = new OperationMethodContext() {  Guid = Guid.NewGuid(), MethodName="call 1", Id = 1};
        MethodRun();
        OperationMethodContext.Current = new OperationMethodContext() {  Guid = Guid.NewGuid(), MethodName="call 2", Id = 2};
        MethodRun();
        OperationMethodContext.Current = new OperationMethodContext() {  Guid = Guid.NewGuid(), MethodName="call 3", Id = 3};
        MethodRun();
        OperationMethodContext.Current = new OperationMethodContext() {  Guid = Guid.NewGuid(), MethodName="call 4", Id = 4};
        MethodRun();
        Console.ReadKey();
    }

    private static async void MethodRun()
    {
        Console.WriteLine("call started: " + OperationMethodContext.Current.MethodName);
        await Task.Delay(2000);
        Console.WriteLine("call finished: " + OperationMethodContext.Current.MethodName);
    }
}

我想获取OperationMethodContext.Current per-method调用,而不将OperationMethodContext作为参数或属性发送,如果我需要更多调用堆栈,我想访问OperationMethodContext.Current per-stack调用。

你知道吗?这些属性是静态的,我想我需要一个像guid这样的值,它在调用时是不同的