System.IDisposable.Dispose()

Here are the examples of the csharp api System.IDisposable.Dispose() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4064 Examples 7

19 View Source File : HasTempFolder.cs
License : MIT License
Project Creator : action-bi-toolkit

public virtual void Dispose()
        {
            (TestFolder as IDisposable)?.Dispose();
        }

19 View Source File : HttpSingleton.cs
License : MIT License
Project Creator : Adoxio

public static void Dispose(string portalName)
		{
			var key = GetKey(portalName);
			var current = HttpContext.Current.Items[key] as IDisposable;

			if (current != null)
			{
				lock (_lock)
				{
					current = HttpContext.Current.Items[key] as IDisposable;

					if (current != null)
					{
						current.Dispose();
					}

					HttpContext.Current.Items[key] = null;
				}
			}
		}

19 View Source File : NetConnection.cs
License : MIT License
Project Creator : a1q123456

protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    lock (_streamsLock)
                    {
                        while (_netStreams.Any())
                        {
                            (_, var stream) = _netStreams.First();
                            if (stream is IDisposable disp)
                            {
                                disp.Dispose();
                            }
                        }
                    }

                    _rtmpChunkStream.Dispose();
                }

                disposedValue = true;
            }
        }

19 View Source File : App.xaml.cs
License : MIT License
Project Creator : Accelerider

protected override void OnExit(ExitEventArgs e)
        {
            if (Container != null)
            {
                Container.Resolve<IUpgradeService>().Stop();
                Container.Resolve<IEventAggregator>().GetEvent<ApplicationExiting>().Publish();
                (Container.Resolve<ILoggerFacade>() as IDisposable)?.Dispose();
            }

            ProcessController.Clear();

            base.OnExit(e);
        }

19 View Source File : WeatherMonitor.cs
License : GNU General Public License v3.0
Project Creator : abishekaditya

public void Unsubscribe()
        {
            _cancellation.Dispose();
        }

19 View Source File : Param_Cloud.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List<Guid> obj_ids) {
            Guid guid = new Guid();
            IEnumerator enumerator = null;
            if (att == null) {
                att = doc.CreateDefaultAttributes();
            }
            try {
                enumerator = this.m_data.GetEnumerator();
                while (enumerator.MoveNext()) {
                    IGH_BakeAwareData current = (IGH_BakeAwareData)enumerator.Current;
                    if (current == null || !current.BakeGeometry(doc, att, out guid)) {
                        continue;
                    }
                    obj_ids.Add(guid);
                }
            } finally {
                if (enumerator is IDisposable) {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

19 View Source File : Arrays.cs
License : MIT License
Project Creator : adamped

public static void DeleteArray<T>(T[] array) where T: System.IDisposable
	{
		foreach (T element in array)
		{
			if (element != null)
				element.Dispose();
		}
	}

19 View Source File : ObjectPool.cs
License : MIT License
Project Creator : 2881099

public void Return(Object<T> obj, bool isReset = false)
        {

            if (obj == null) return;

            if (obj._isReturned) return;

            if (running == false)
            {

                Policy.OnDestroy(obj.Value);
                try { (obj.Value as IDisposable)?.Dispose(); } catch { }

                return;
            }

            if (isReset) obj.ResetValue();

            bool isReturn = false;

            while (isReturn == false && _getQueue.TryDequeue(out var isAsync))
            {

                if (isAsync == false)
                {

                    if (_getSyncQueue.TryDequeue(out var queueItem) && queueItem != null)
                    {

                        lock (queueItem.Lock)
                            if (queueItem.IsTimeout == false)
                                queueItem.ReturnValue = obj;

                        if (queueItem.ReturnValue != null)
                        {

                            obj.LastReturnThreadId = Thread.CurrentThread.ManagedThreadId;
                            obj.LastReturnTime = DateTime.Now;

                            try
                            {
                                queueItem.Wait.Set();
                                isReturn = true;
                            }
                            catch
                            {
                            }
                        }

                        try { queueItem.Dispose(); } catch { }
                    }

                }
                else
                {

                    if (_getAsyncQueue.TryDequeue(out var tcs) && tcs != null && tcs.Task.IsCanceled == false)
                    {

                        obj.LastReturnThreadId = Thread.CurrentThread.ManagedThreadId;
                        obj.LastReturnTime = DateTime.Now;

                        try { isReturn = tcs.TrySetResult(obj); } catch { }
                    }
                }
            }

            //无排队,直接归还
            if (isReturn == false)
            {
                try
                {
                    Policy.OnReturn(obj);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    obj.LastReturnThreadId = Thread.CurrentThread.ManagedThreadId;
                    obj.LastReturnTime = DateTime.Now;
                    obj._isReturned = true;

                    _freeObjects.Push(obj);
                }
            }
        }

19 View Source File : Parallel.cs
License : MIT License
Project Creator : adrenak

private void Dispose(bool disposing) {
                if (disposing) {
                    // dispose managed resources
                    this.enumerator.Dispose();
                    foreach (WorkerThread worker in this.workerThreads) {
                        worker.Dispose();
                    }
                    this.workerThreads.Clear();
                }
                // free native resources
            }

19 View Source File : Object.cs
License : MIT License
Project Creator : 2881099

public void ResetValue()
        {
            if (this.Value != null)
            {
                try { this.Pool.Policy.OnDestroy(this.Value); } catch { }
                try { (this.Value as IDisposable)?.Dispose(); } catch { }
            }
            T value = default(T);
            try { value = this.Pool.Policy.OnCreate(); } catch { }
            this.Value = value;
            this.LastReturnTime = DateTime.Now;
        }

19 View Source File : RemoteModuleTypeLoader.cs
License : MIT License
Project Creator : Accelerider

protected virtual void Dispose(bool disposing)
        {
            var disposableResolver = _replacedemblyResolver as IDisposable;
            disposableResolver?.Dispose();
        }

19 View Source File : CollectionsExtensions.cs
License : Apache License 2.0
Project Creator : abist-co-ltd

public static void DisposeElements<TElement>(this IList<TElement> elements)
            where TElement : IDisposable
        {
            for (int iElement = 0; iElement < elements.Count; iElement++)
            {
                var element = elements[iElement];

                if (element != null)
                {
                    element.Dispose();
                }
            }
        }

19 View Source File : GH_Cloud.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

public override IGH_GeometricGoo Transform(Transform xform) {
            IGH_GeometricGoo gHGeometricGoo;
            IEnumerator<PointCloudItem> enumerator = null;
            if (this.IsValid) {
                this.m_value.Transform(xform);
                if (this.m_value.ContainsNormals) {
                    try {
                        enumerator = this.m_value.GetEnumerator();
                        while (enumerator.MoveNext()) {
                            PointCloudItem current = enumerator.Current;
                            Vector3d normal = current.Normal;
                            normal.Transform(xform);
                            current.Normal=(normal);
                        }
                    } finally {
                        if (enumerator != null) {
                            enumerator.Dispose();
                        }
                    }
                }
                this.ReferenceID = Guid.Empty;
                this.ScanPos.Transform(xform);
                gHGeometricGoo = this;
            } else {
                gHGeometricGoo = null;
            }
            return gHGeometricGoo;
        }

19 View Source File : FileDownloader.cs
License : MIT License
Project Creator : Accelerider

protected virtual void Dispose(bool disposing)
        {
            if (Status == TransferStatus.Disposed) return;

            if (disposing)
            {
                _cancellationTokenSource?.Cancel();
                _disposable?.Dispose();
            }
        }

19 View Source File : HttpStreamParser.cs
License : MIT License
Project Creator : 1iveowl

public void Dispose()
        {
            _disposableParserCompletion?.Dispose();
            _parser?.Dispose();
        }

19 View Source File : VssConnection.cs
License : MIT License
Project Creator : actions

public void Dispose()
        {
            if (!m_isDisposed)
            {
                lock (m_disposeLock)
                {
                    if (!m_isDisposed)
                    {
                        m_isDisposed = true;
                        foreach (var cachedType in m_cachedTypes.Values.Where(v => v is IDisposable).Select(v => v as IDisposable))
                        {
                            cachedType.Dispose();
                        }
                        m_cachedTypes.Clear();
                        Disconnect();
                        if (m_parentConnection != null)
                        {
                            m_parentConnection.Dispose();
                            m_parentConnection = null;
                        }
                    }
                }
            }
        }

19 View Source File : SerializationContext.cs
License : MIT License
Project Creator : a1q123456

public void Dispose()
        {
            if (_disposeBuffer)
            {
                ((IDisposable)Buffer).Dispose();
            }
        }

19 View Source File : CrmDbContext.cs
License : MIT License
Project Creator : Adoxio

protected virtual void Dispose(bool disposing)
		{
			if (DisposeContext && disposing)
			{
				var service = Service as IDisposable;

				if (service != null)
				{
					service.Dispose();
					Service = null;
				}
			}
		}

19 View Source File : Program.cs
License : MIT License
Project Creator : 0xDivyanshu

static byte[] aes_decryption(byte[] shellcode, string preplacedword)
        {
            string iv = "1234567891234567";
            AesCryptoServiceProvider keydecrypt = new AesCryptoServiceProvider();
            keydecrypt.BlockSize = 128;
            keydecrypt.KeySize = 128;
            keydecrypt.Key = System.Text.Encoding.UTF8.GetBytes(preplacedword);
            keydecrypt.IV = System.Text.Encoding.UTF8.GetBytes(iv);
            keydecrypt.Padding = PaddingMode.PKCS7;
            keydecrypt.Mode = CipherMode.CBC;
            ICryptoTransform crypto1 = keydecrypt.CreateDecryptor(keydecrypt.Key, keydecrypt.IV);

            byte[] returnbytearray = crypto1.TransformFinalBlock(shellcode, 0, shellcode.Length);
            crypto1.Dispose();
            return returnbytearray;
        }

19 View Source File : CrmOrganizationServiceContext.cs
License : MIT License
Project Creator : Adoxio

protected override void Dispose(bool disposing)
		{
			if (disposing && _shouldDisposeService)
			{
				var service = _service as IDisposable;

				if (service != null)
				{
					service.Dispose();
				}
			}

			base.Dispose(disposing);
		}

19 View Source File : WebSocketSession.cs
License : MIT License
Project Creator : a1q123456

internal void HandleClose()
        {
            if (_controller is IDisposable disp)
            {
                disp.Dispose();
            }
            _controller = null;
        }

19 View Source File : Program.cs
License : MIT License
Project Creator : ab4d

public static void Dispose(IDisposable disposable)
		{
			if(disposable != null)
				disposable.Dispose();
		}

19 View Source File : Helper.cs
License : MIT License
Project Creator : 0xDivyanshu

static byte[] Encrypt(byte[] data,string Key, string IV)
        {
            AesCryptoServiceProvider dataencrypt = new AesCryptoServiceProvider();
            dataencrypt.BlockSize = 128;
            dataencrypt.KeySize = 128;
            dataencrypt.Key = System.Text.Encoding.UTF8.GetBytes(Key);
            dataencrypt.IV = System.Text.Encoding.UTF8.GetBytes(IV);
            dataencrypt.Padding = PaddingMode.PKCS7;
            dataencrypt.Mode = CipherMode.CBC;
            ICryptoTransform crypto1 = dataencrypt.CreateEncryptor(dataencrypt.Key, dataencrypt.IV);
            byte[] encrypteddata = crypto1.TransformFinalBlock(data, 0, data.Length);
            crypto1.Dispose();
            return encrypteddata;
        }

19 View Source File : CollectionsExtensions.cs
License : Apache License 2.0
Project Creator : abist-co-ltd

public static void DisposeElements<TElement>(this IEnumerable<TElement> elements)
            where TElement : IDisposable
        {
            foreach (var element in elements)
            {
                if (element != null)
                {
                    element.Dispose();
                }
            }
        }

19 View Source File : Store.cs
License : MIT License
Project Creator : 71

internal void Dispose(Action<Exception> logException)
        {
            var values = Values.UnderlyingArray;

            for (int i = 0; i < values.Length; i++)
            {
                if (!(values[i] is IDisposable disposable))
                    continue;

                try
                {
                    disposable.Dispose();
                }
                catch (Exception e)
                {
                    // Eh.
                    logException(e);
                }
            }
        }

19 View Source File : FrmCaptcha.Designer.cs
License : MIT License
Project Creator : ACBrNet

protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

19 View Source File : VitalSignsMonitorView.xaml.cs
License : MIT License
Project Creator : ABTSoftware

private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            _dataSubscription.Dispose();
        }

19 View Source File : ControlDisplay.cs
License : GNU Lesser General Public License v3.0
Project Creator : 9and3

[DebuggerNonUserCode]
        protected override void Dispose(bool disposing) {
            try {
                if (disposing && this.components != null) {
                    this.components.Dispose();
                }
            } finally {
                base.Dispose(disposing);
            }
        }

19 View Source File : FileDownloaderManager.cs
License : MIT License
Project Creator : Accelerider

private IDisposable ObserveDownloader(IDownloader downloader)
        {
            var id = downloader.Id;

            var disposable = downloader
                .Distinct(item => item.Status)
                .Subscribe(item =>
                {
                    switch (item.Status)
                    {
                        case TransferStatus.Ready:
                            MoveToTail(_pendingList, id, _executingList, _suspendedList);
                            break;
                        case TransferStatus.Transferring:
                            MoveToTop(_executingList, id, _pendingList, _suspendedList);
                            break;
                        case TransferStatus.Suspended:
                            MoveToTop(_suspendedList, id, _executingList);
                            break;
                        case TransferStatus.Disposed:
                            DequeueById(id);
                            break;
                    }
                    Advance();
                }, error =>
                {
                    MoveToTail(_suspendedList, id, _executingList, _pendingList);
                    Advance();
                }, () =>
                {
                    MoveToTop(_completedList, id, _executingList, _pendingList, _suspendedList);
                    if (_observers.TryRemove(id, out var token))
                    {
                        token.Dispose();
                    }
                    Advance();
                });

            _observers.TryAdd(id, disposable);

            return disposable;
        }

19 View Source File : MainPage.xaml.cs
License : MIT License
Project Creator : 1iveowl

private void Stop_OnClick(object sender, RoutedEventArgs e)
        {
            _disposable.Dispose();
        }

19 View Source File : SixCloudUser.cs
License : MIT License
Project Creator : Accelerider

private void SaveDownloadingFile(IDownloadingFile result)
        {
            _downloadingFiles.Add(result);
            ArddFilePaths.Add(result.ArddFilePath);

            var disposable1 = Subscribe(result.DownloadInfo.Where(item => item.Status == TransferStatus.Suspended || item.Status == TransferStatus.Faulted));
            var disposable2 = Subscribe(result.DownloadInfo.Sample(TimeSpan.FromMilliseconds(5000)));

            result.DownloadInfo
                .Where(item => item.Status == TransferStatus.Disposed)
                .Subscribe(async _ =>
                {
                    await ClearDownloadInfo(true);

                    Logger.Info($"Download Cancelled: {result.DownloadInfo.Context.LocalPath}. ");
                }, OnCompleted);

            File.WriteAllText(result.ArddFilePath.EnsureFileFolder(), result.ToJsonString());

            if (result.DownloadInfo.Status == TransferStatus.Completed)
            {
                OnCompleted();
            }

            async void OnCompleted()
            {
                await ClearDownloadInfo(false);
                var localDiskFile = LocalDiskFile.Create(result);
                _localDiskFiles.Add(localDiskFile);

                Logger.Info($"Download Completed: {result.DownloadInfo.Context.LocalPath}. ");
            }

            IDisposable Subscribe(IObservable<TransferNotification> observable)
            {
                return observable.Subscribe(_ => File.WriteAllText(result.ArddFilePath, result.ToJsonString()));
            }

            async Task ClearDownloadInfo(bool isCancelled)
            {
                disposable1.Dispose();
                disposable2.Dispose();

                ArddFilePaths.Remove(result.ArddFilePath);
                _downloadingFiles.Remove(result);

                await result.ArddFilePath.TryDeleteAsync();
                if (isCancelled) await result.DownloadInfo.Context.LocalPath.TryDeleteAsync();
            }
        }

19 View Source File : JobFactory.cs
License : Apache License 2.0
Project Creator : 91270

public void ReturnJob(IJob job)
        {
            var disposable = job as IDisposable;
            if (disposable != null)
            {
                disposable.Dispose();
            }

        }

19 View Source File : HostContext.cs
License : MIT License
Project Creator : actions

private void Dispose(bool disposing)
        {
            // TODO: Dispose the trace listener also.
            if (disposing)
            {
                if (_loadContext != null)
                {
                    _loadContext.Unloading -= LoadContext_Unloading;
                    _loadContext = null;
                }
                _httpTraceSubscription?.Dispose();
                _diagListenerSubscription?.Dispose();
                _traceManager?.Dispose();
                _traceManager = null;

                _runnerShutdownTokenSource?.Dispose();
                _runnerShutdownTokenSource = null;

                base.Dispose();
            }
        }

19 View Source File : DisposableUtil.cs
License : GNU Lesser General Public License v3.0
Project Creator : 0xC0000054

public static void Free<TDisposable>(ref TDisposable disposable) where TDisposable : clreplaced, IDisposable
        {
            if (disposable != null)
            {
                disposable.Dispose();
                disposable = null;
            }
        }

19 View Source File : ExpressionNode.cs
License : MIT License
Project Creator : actions

EvaluationResult IExpressionNode.Evaluate(
            ITraceWriter trace,
            ISecretMasker secretMasker,
            Object state,
            EvaluationOptions options)
        {
            if (Container != null)
            {
                // Do not localize. This is an SDK consumer error.
                throw new NotSupportedException($"Expected {nameof(IExpressionNode)}.{nameof(Evaluate)} to be called on root node only.");
            }


            var originalSecretMasker = secretMasker;
            try
            {
                // Evaluate
                secretMasker = secretMasker?.Clone() ?? new SecretMasker();
                trace = new EvaluationTraceWriter(trace, secretMasker);
                var context = new EvaluationContext(trace, secretMasker, state, options, this);
                trace.Info($"Evaluating: {ConvertToExpression()}");
                var result = Evaluate(context);

                // Trace the result
                TraceTreeResult(context, result.Value, result.Kind);

                return result;
            }
            finally
            {
                if (secretMasker != null && secretMasker != originalSecretMasker)
                {
                    (secretMasker as IDisposable)?.Dispose();
                    secretMasker = null;
                }
            }
        }

19 View Source File : ClientForm1.Designer.cs
License : MIT License
Project Creator : a11s

protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

19 View Source File : FileLoggerProvider.cs
License : MIT License
Project Creator : adams85

private bool TryDisposeAsync(bool completeProcessorOnThreadPool, out Task completeProcessorTask)
        {
            lock (_loggers)
                if (!_isDisposed)
                {
                    _settingsChangeToken?.Dispose();

                    completeProcessorTask =
                        completeProcessorOnThreadPool ?
                        Task.Run(() => Processor.CompleteAsync()) :
                        Processor.CompleteAsync();

                    DisposeCore();

                    _isDisposed = true;
                    return true;
                }

            completeProcessorTask = null;
            return false;
        }

19 View Source File : AreaForm.cs
License : MIT License
Project Creator : 1CM69

protected override void Dispose(bool disposing)
        {
            if (disposing && this.components != null)
                this.components.Dispose();
            base.Dispose(disposing);
        }

19 View Source File : BaseManager.cs
License : MIT License
Project Creator : Adoxio

protected virtual void Dispose(bool disposing)
		{
			if (_disposed) return;

			if (disposing)
			{
				Store.Dispose();
			}

			Store = null;
			_disposed = true;
		}

19 View Source File : ChunkStreamContext.cs
License : MIT License
Project Creator : a1q123456

public void Dispose()
        {
            ((IDisposable)_rtmpSession).Dispose();
        }

19 View Source File : TreeNode.cs
License : MIT License
Project Creator : Adoxio

public void Dispose()
		{
			if (!(Value is IDisposable)) return;

			foreach (var node in Children.Cast<TreeNode<T>>())
			{
				node.Dispose();
			}

			(Value as IDisposable).Dispose();
		}

19 View Source File : WorkshopQueryBase.cs
License : MIT License
Project Creator : 0x0ade

protected virtual void Dispose(bool flag) {
        Destroy();

        _completedCallResult?.Cancel();
        (_completedCallResult as IDisposable)?.Dispose();
        _completedCallResult = null;
    }

19 View Source File : DeploymentService.cs
License : MIT License
Project Creator : Adoxio

public virtual void Dispose()
		{
			var service = _service.Value as IDisposable;

			if (service != null)
			{
				service.Dispose();
			}
		}

19 View Source File : RtmpSession.cs
License : MIT License
Project Creator : a1q123456

public void DeleteNetStream(uint id)
        {
            if (NetConnection.NetStreams.TryGetValue(id, out var stream))
            {
                if (stream is IDisposable disp)
                {
                    disp.Dispose();
                }
                NetConnection.RemoveMessageStream(id);
            }
        }

19 View Source File : ObjectPool.cs
License : MIT License
Project Creator : 2881099

public void Dispose()
        {

            running = false;

            while (_freeObjects.TryPop(out var fo)) ;

            while (_getSyncQueue.TryDequeue(out var sync))
            {
                try { sync.Wait.Set(); } catch { }
            }

            while (_getAsyncQueue.TryDequeue(out var async))
                async.TrySetCanceled();

            while (_getQueue.TryDequeue(out var qs)) ;

            for (var a = 0; a < _allObjects.Count; a++)
            {
                Policy.OnDestroy(_allObjects[a].Value);
                try { (_allObjects[a].Value as IDisposable)?.Dispose(); } catch { }
            }

            _allObjects.Clear();
        }

19 View Source File : Form1.Designer.cs
License : GNU General Public License v3.0
Project Creator : 00000vish

protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

19 View Source File : DisposableLazy.cs
License : GNU Lesser General Public License v3.0
Project Creator : 0xC0000054

public void Dispose()
        {
            if (this.IsValueCreated)
            {
                this.Value.Dispose();
            }
        }

19 View Source File : Dumper.cs
License : MIT License
Project Creator : 13xforever

public void Dispose()
        {
            driveStream?.Dispose();
            ((IDisposable)Decrypter)?.Dispose();
            Cts?.Dispose();
        }

19 View Source File : IoCBindData.cs
License : MIT License
Project Creator : 7Bytes-Studio

public void OnRelease()
        {
            IDisposable disposableInstance = null;
            if (null!=Instance)
            {
                disposableInstance = Instance as IDisposable;
                if (null != disposableInstance)
                {
                    disposableInstance.Dispose();
                }
                Instance = null;
            }

            if (null != SingleInstance)
            {
                disposableInstance = SingleInstance as IDisposable;
                if (null != disposableInstance)
                {
                    disposableInstance.Dispose();
                }
                SingleInstance = null;
            }

            if (0<m_InstanceList.Count)
            {
                for (int i = 0; i < m_InstanceList.Count; i++)
                {
                    disposableInstance = m_InstanceList[i] as IDisposable;
                    if (null != disposableInstance)
                    {
                        disposableInstance.Dispose();
                    }
                }
            }
            m_InstanceList.Clear();
        }

19 View Source File : YAxisSameZeroLine.xaml.cs
License : MIT License
Project Creator : ABTSoftware

public void Dispose()
            {
                Subscription?.Dispose();
            }

See More Examples