Example #1
0
 public static async Task DisposeAsync(this IPackageIndex packageIndex, IExportProvider exportProvider) {
     var sessionProvider = exportProvider.GetExportedValue<IRInteractiveWorkflowProvider>().GetOrCreate().RSessions;
     if (sessionProvider != null) {
         await Task.WhenAll(sessionProvider.GetSessions().Select(s => s.StopHostAsync()));
     }
     packageIndex?.Dispose();
 } 
		/// <summary>
		/// LOLLO Disposes of a semaphore.
		/// You can use this method to interrupt all operations, which are queuing at the semaphore, if you initialised it for max 1 thread.
		/// Wait at the semaphore before calling this method, to be sure you don't disrupt any running operations at an unexpected moment.
		/// Every method using this semaphore should make allowance for it being disposed, eg
		/// try
		/// {
		///     semaphore.Wait();
		///     do some work
		/// }
		/// catch (Exception ex)
		/// {
		///     if (SemaphoreExtensions.IsAlive(semaphore))
		///         // you have a real error, otherwise it's simply the semaphore being disposed and reset to null
		/// }
		/// finally
		/// {
		///     SemaphoreExtensions.TryRelease(semaphore);
		///     // do not just call semaphore.Release() because the semaphore may be disposed or null at this stage
		/// }
		/// </summary>
		/// <param name="semaphore"></param>
		/// <returns></returns>
		public static bool TryDispose(this Semaphore semaphore)
		{
			try
			{
				semaphore?.Dispose();
				return true;
			}
			catch { }
			return false;
		}