Skip to content

Instantly share code, notes, and snippets.

@Criteo-dotnet-blog
Created December 22, 2017 13:34
Show Gist options
  • Select an option

  • Save Criteo-dotnet-blog/173f517c0e5c28629bb4fc760f5654e8 to your computer and use it in GitHub Desktop.

Select an option

Save Criteo-dotnet-blog/173f517c0e5c28629bb4fc760f5654e8 to your computer and use it in GitHub Desktop.
private ThreadPoolItem GetQueueUserWorkItemCallback(dynamic element)
{
    ThreadPoolItem tpi = new ThreadPoolItem()
    {
        Address = (ulong)element,
        Type = ThreadRoot.WorkItem
    };
    // look for the callback given to ThreadPool.QueueUserWorkItem()
    var callback = element.callback;
    if (callback == null)
    {
        tpi.MethodName = "[no callback]";
        return tpi;
    }
    var target = callback._target;
    if (target == null)
    {
        tpi.MethodName = "[no callback target]";
        return tpi;
    }
    ClrType targetType = target.GetClrType();
    if (targetType == null)
    {
        tpi.MethodName = $" [target=0x{(ulong)target}]";
    }
    else
    {
        // look for method name
        tpi.MethodName = BuildDelegateMethodName(targetType, callback);
    }
    return tpi;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment