Skip to content

Instantly share code, notes, and snippets.

@HauVuTri
HauVuTri / gist:6c2e35117d616e4eed134368e4cb81b2
Created December 25, 2024 09:55
GetServiceExecutablePath
private string GetServiceExecutablePath(string serviceName)
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey($@"SYSTEM\CurrentControlSet\Services\{serviceName}"))
{
if (key != null)
{
var imagePath = key.GetValue("ImagePath") as string;
if (!string.IsNullOrEmpty(imagePath))
{
// Trim surrounding quotes if any
@HauVuTri
HauVuTri / gist:398bf40f731a3a1a0aa4ab5a95208757
Created December 20, 2024 09:48
use SemaphoreSlim for multitasking
var semaphore = new SemaphoreSlim(50);//50 là max số task đồng thời
var downloadTasks = lstIds.Select(async id =>
{
await semaphore.WaitAsync();
try
{
//Xử lý logic ở đây
return individualMsg;
}
finally