in src/DotNetWorker.Core/StartupHook.cs [26:72]
public static void Initialize()
{
// Time to wait between checks, in ms.
const int SleepTime = 500;
const int MaxWaitCycles = (60 * 1000) / SleepTime;
RemoveSelfFromStartupHooks();
string? debuggerWaitEnabled = Environment.GetEnvironmentVariable("FUNCTIONS_ENABLE_DEBUGGER_WAIT");
string? jsonOutputEnabled = Environment.GetEnvironmentVariable("FUNCTIONS_ENABLE_JSON_OUTPUT");
#if NET6_0_OR_GREATER
int processId = Environment.ProcessId;
#else
int processId = Process.GetCurrentProcess().Id;
#endif
static bool WaitOnDebugger(int cycle)
{
if (Debugger.IsAttached)
{
return false;
}
if (cycle > MaxWaitCycles)
{
Console.WriteLine("A debugger was not attached within the expected time limit. The process will continue without a debugger.");
return false;
}
return true;
}
if (string.Equals(jsonOutputEnabled, bool.TrueString, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine($"azfuncjsonlog:{{ \"name\":\"dotnet-worker-startup\", \"workerProcessId\" : {processId} }}");
}
if (string.Equals(debuggerWaitEnabled, bool.TrueString, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine($"Azure Functions .NET Worker (PID: {processId}) initialized in debug mode. Waiting for debugger to attach...");
for (int i = 0; WaitOnDebugger(i); i++)
{
Thread.Sleep(SleepTime);
}
}
}