Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Remove SpinWait
Browse files Browse the repository at this point in the history
Use Task.Wait instead to avoid CPU use.
  • Loading branch information
mrward committed Nov 27, 2018
1 parent 67cd093 commit 74ce91a
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions Mono.Addins.Setup/Mono.Addins.Setup/AddinStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,7 @@ internal string DownloadFile (IProgressMonitor monitor, string url)
try {
monitor.BeginTask ("Requesting " + url, 2);
var task = DownloadFileRequest.DownloadFile (url, noCache: true);
if (!WaitForTask (task, monitor))
throw new InstallException ("Installation cancelled.");
task.Wait ();

using (var request = task.Result) {
monitor.Step (1);
Expand Down Expand Up @@ -679,19 +678,6 @@ internal string DownloadFile (IProgressMonitor monitor, string url)
}
}

static bool WaitForTask (Task<DownloadFileRequest> task, IProgressMonitor monitor)
{
bool result = SpinWait.SpinUntil (() => {
return monitor.IsCancelRequested || task.IsCompleted || task.IsFaulted;
}, 100000); // Use same default timeout as HttpClient.

if (monitor.IsCancelRequested)
return false;
if (!result)
throw new InstallException ("Timed out.");
return result;
}

internal bool HasWriteAccess (string file)
{
FileInfo f = new FileInfo (file);
Expand Down

0 comments on commit 74ce91a

Please sign in to comment.