Skip to content

ServiceManager.UninstallServiceAsync: Thread.Sleep blocks thread pool thread in async method #162

@Christophe-Rogiers

Description

@Christophe-Rogiers

Bug

UninstallServiceAsync uses Thread.Sleep(500) in a polling loop while waiting for a service to stop:

while (sc.Status != ServiceControllerStatus.Stopped && DateTime.Now < waitUntil)
{
    Thread.Sleep(500); // Blocks thread pool thread
    sc.Refresh();
}

Since this is an async method, Thread.Sleep blocks the thread pool thread instead of yielding it.

Impact

Under load (e.g. bulk uninstall operations), this can exhaust thread pool threads and degrade application responsiveness.

Suggested fix

Replace with await Task.Delay(500).

File

src/Servy.Core/Services/ServiceManager.cs — line 570

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions