{"id":22396853,"url":"https://github.com/codedead/deadlock-dotnet-sdk","last_synced_at":"2025-07-31T12:31:18.503Z","repository":{"id":41984512,"uuid":"482855828","full_name":"CodeDead/deadlock-dotnet-sdk","owner":"CodeDead","description":"DeadLock SDK that allows developers to unlock files that cannot be removed on Windows","archived":false,"fork":false,"pushed_at":"2023-05-16T06:56:25.000Z","size":35,"stargazers_count":6,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T01:51:23.179Z","etag":null,"topics":["codedead","csharp","deadlock","dotnet","dotnet-6","dotnet6","file","file-handle","filehandle","filehandles","files","filesystem","folder","handle","handles","windows"],"latest_commit_sha":null,"homepage":"https://codedead.com","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeDead.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-18T13:25:09.000Z","updated_at":"2024-07-27T19:13:02.000Z","dependencies_parsed_at":"2023-01-20T02:04:16.547Z","dependency_job_id":null,"html_url":"https://github.com/CodeDead/deadlock-dotnet-sdk","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/CodeDead/deadlock-dotnet-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeDead%2Fdeadlock-dotnet-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeDead%2Fdeadlock-dotnet-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeDead%2Fdeadlock-dotnet-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeDead%2Fdeadlock-dotnet-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeDead","download_url":"https://codeload.github.com/CodeDead/deadlock-dotnet-sdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeDead%2Fdeadlock-dotnet-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268039868,"owners_count":24185809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codedead","csharp","deadlock","dotnet","dotnet-6","dotnet6","file","file-handle","filehandle","filehandles","files","filesystem","folder","handle","handles","windows"],"created_at":"2024-12-05T06:09:32.624Z","updated_at":"2025-07-31T12:31:18.181Z","avatar_url":"https://github.com/CodeDead.png","language":"C#","readme":"﻿# deadlock-dotnet-sdk\n\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/CodeDead/deadlock-dotnet-sdk)\n![Nuget](https://img.shields.io/nuget/v/deadlock-dotnet-sdk)\n![GitHub](https://img.shields.io/badge/language-C%23-green)\n![GitHub](https://img.shields.io/github/license/CodeDead/deadlock-dotnet-sdk)\n\ndeadlock-dotnet-sdk is a simple-to-use SDK for unlocking files in C# / dotnet on Windows based operating systems.\n\n## Usage\n\nAdd deadlock-dotnet-sdk to your solution tree using [NuGet](https://www.nuget.org/packages/deadlock-dotnet-sdk/):\n```shell\nInstall-Package deadlock-dotnet-sdk\n```\n\nYou can initialize a new `DeadLock` helper object like so:\n```c#\nDeadLock deadLock = new DeadLock();\n```\n\nIn addition, if you would like to rethrow inner exceptions, you can change the `RethrowExceptions` property when declaring a new `DeadLock` object:\n```c#\nDeadLock deadLock = new DeadLock(`true` | `false`);\n```\n\nYou can also change the property dynamically:\n```c#\ndeadlock.RethrowExceptions = `true` | `false`\n```\n\n### Finding the processes that are locking a file\n\nTo find all the `FileLocker` objects that are locking a file, you can make use of the `FindLockingProcesses` method:\n```c#\nstring path = @\"C:\\...\\file.txt\";\nList\u003cFileLocker\u003e lockers = DeadLock.FindLockingProcesses(path);\n```\n\nYou can also run the code asynchronously by calling the `FindLockingProcessesAsync` method`:\n```c#\nstring path = @\"C:\\...\\file.txt\";\nList\u003cFileLocker\u003e lockers = await DeadLock.FindLockingProcessesAsync(path);\n```\n\nTo find the `Process` objects that are locking one or more files, you can invoke the `FindLockingProcesses` (or `FindLockingProcessesAsync`) method with multiple `path` parameters:\n```c#\nList\u003cFileLocker\u003e fileLockers = FindLockingProcesses(\"a\", \"c\", \"c\");\n```\n\n### Unlocking a file\n\nTo unlock a `FileLocker`, you can execute the  `Unlock` method:\n```c#\nDeadLock.Unlock(locker);\n```\n\nYou can also run the code asynchronously by running the `UnlockAsync` method:\n```c#\nawait DeadLock.UnlockAsync(locker);\n```\n\nTo unlock more than one `FileLocker` object, you can invoke the `Unlock` (or `UnlockAsync`) method with multiple `FileLocker` parameters:\n```c#\nUnlock(fileLockerA, fileLockerB, fileLockerC);\n```\n\nAlternatively, if you only want to unlock a file and you are not interested in using the `FileLocker` objects, you can do so by providing any of the `Unlock` or `UnlockAsync` methods with one or more `string` variables that represent the path or paths of the file(s) that should be unlocked:\n```c#\n// Unlock a single path\nstring path = @\"C:\\...\\file.txt\"; \nUnlock(path);\n\n// Unlock multiple files\nUnlock(path1, path2, path3);\n\n// Asynchronously unlock one or more files\nawait UnlockAsync(path);\nawait UnlockAsync(path1, path2, path3);\n```\n\n### `FileLocker`\n\nThe `FileLocker` object contains a `List` of `System.Diagnostics.Process` objects that are locking a file.\nYou can retrieve the `List` of `Process` objects by retrieving the respective property:\n```c#\nList\u003cProcess\u003e processes = fileLocker.Lockers;\n```\n\nTo retrieve the path of the file that the `Process` objects are locking, you can make use of the `Path` property:\n```c#\nstring path = fileLocker.Path;\n```\n\n### Error handling\n\ndeadlock-dotnet-sdk has three specific `Exception` types that might occur when trying to find the `Process` objects that are locking a file.\n\n* `RegisterResourceException`\n* `RmListException`\n* `StartSessionException`\n\nIn case you want more detailed error messages, it is recommended that you call the `Marshal.GetLastWin32Error` method as soon as one of these `Exception` types occur:  \nhttps://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.getlastwin32error?view=net-6.0\n\n#### `RegisterResourceException`\n\nThis error occurs when the system goes out of memory, when a specific time-out occurs or if an invalid handle is detected. You can find more information about this exception here:  \nhttps://docs.microsoft.com/en-us/windows/win32/api/restartmanager/nf-restartmanager-rmregisterresources#return-value\n\n#### `RmListException`\n\nThis error occurs when the system goes out of memory, when a specific time-out occurs or if an invalid handle is detected. You can find more information about this exception here:  \nhttps://docs.microsoft.com/en-us/windows/win32/api/restartmanager/nf-restartmanager-rmgetlist#return-value\n\n#### `StartSessionException`\n\nThis error occurs when the system goes out of memory, when a specific time-out occurs or if an invalid handle is detected. You can find more information about this exception here:  \nhttps://docs.microsoft.com/en-us/windows/win32/api/restartmanager/nf-restartmanager-rmstartsession#return-value\n\n## Credits\n\n* [RemixIcon](https://remixicon.com/)\n* [dotnet](https://dotnet.microsoft.com/en-us/)\n\n## About\n\nThis library is maintained by CodeDead. You can find more about us using the following links:\n* [Website](https://codedead.com)\n* [Twitter](https://twitter.com/C0DEDEAD)\n* [Facebook](https://facebook.com/deadlinecodedead)\n\nCopyright © 2022 CodeDead\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodedead%2Fdeadlock-dotnet-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodedead%2Fdeadlock-dotnet-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodedead%2Fdeadlock-dotnet-sdk/lists"}