CLR メモリ診断ライブラリを使用して、実行中のプロセスのすべてのスレッドのスタック トレースを取得しています。
var result = new Dictionary<int, string[]>();
var pid = Process.GetCurrentProcess().Id;
using (var dataTarget = DataTarget.AttachToProcess(pid, 5000, AttachFlag.Passive))
{
string dacLocation = dataTarget.ClrVersions[0].TryGetDacLocation();
var runtime = dataTarget.CreateRuntime(dacLocation); //throws exception
foreach (var t in runtime.Threads)
{
result.Add(
t.ManagedThreadId,
t.StackTrace.Select(f =>
{
if (f.Method != null)
{
return f.Method.Type.Name + "." + f.Method.Name;
}
return null;
}).ToArray()
);
}
}
ここからこのコードを取得しましたが、他の人にとっては機能しているようですが、指定された行で例外がスローされ、次のメッセージが表示されますThis runtime is not initialized and contains no data.
dacLocation
として設定されていますC:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\mscordacwks.dll