public async Task DeletePackageAsync(LocalPackageInfo packageInfo) { if (packageInfo == null) { throw new ArgumentNullException(nameof(packageInfo)); } // first mark for deletion Task waitForReleaseLocksTask; lock (packagesLock) { if (packageInfo.LockProvider.IsMarkedToDelete) { return; } waitForReleaseLocksTask = packageInfo.LockProvider.MarkForDelete(); } // notify we are deleting package (stop download) LocalPackageDeleting?.Invoke(packageInfo); // wait for all resources all unlocked await waitForReleaseLocksTask; // delete content localPackageManager.DeletePackage(packageInfo); // update collections UpdateLists(addToLocal: null, removeFromLocal: new[] { packageInfo }, addToDiscovered: null); // notify we have deleted package (stop download) LocalPackageDeleted?.Invoke(packageInfo); }