MCPcopy Create free account
hub / github.com/Squirrel/Squirrel.Windows / acquireUpdateLock

Method acquireUpdateLock

src/Squirrel/UpdateManager.cs:265–288  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

263 }
264
265 Task<IDisposable> acquireUpdateLock()
266 {
267 if (updateLock != null) return Task.FromResult(updateLock);
268
269 return Task.Run(() => {
270 var key = Utility.CalculateStreamSHA1(new MemoryStream(Encoding.UTF8.GetBytes(rootAppDirectory)));
271
272 IDisposable theLock;
273 try {
274 theLock = ModeDetector.InUnitTestRunner() ?
275 Disposable.Create(() => {}) : new SingleGlobalInstance(key, TimeSpan.FromMilliseconds(2000));
276 } catch (TimeoutException) {
277 throw new TimeoutException("Couldn't acquire update lock, another instance may be running updates");
278 }
279
280 var ret = Disposable.Create(() => {
281 theLock.Dispose();
282 updateLock = null;
283 });
284
285 updateLock = ret;
286 return ret;
287 });
288 }
289
290 /// <summary>
291 /// Calculates the total percentage of a specific step that should report within a specific range.

Callers

nothing calls this directly

Calls 5

RunMethod · 0.80
CalculateStreamSHA1Method · 0.80
InUnitTestRunnerMethod · 0.45
CreateMethod · 0.45
DisposeMethod · 0.45

Tested by

no test coverage detected