I know you can determine if a debugger is attached by using System.Diagnostics.Debugger.IsAttached
, but is there a way of determining if a profiler is attached?
My profiler can't trace tasks through the threadpool so I want to automaticly disable parallelism when profiling.
For the standard profiler interface, an environment variable needs to be set.
I guess you can just check this via the Environment
class.
The variable is called COR_ENABLE_PROFILING
and if enabled, will be set to 1
.
Debugger.IsAttached code is included whether debug or release build. And a debugger can be attached to release builds to.
Hence System.Diagnostics.Debugger.IsAttached
would return False if no debugger (or profiler) is attached.
Note: I am not sure about SlimTune but Profilers you tend to attach to the process: How to: Attach and Detach the Profiler to Running Processes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With