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
19
Source : Form1.Designer.cs
with GNU General Public License v3.0
from 00000vish
with GNU General Public License v3.0
from 00000vish
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
19
Source : WorkshopQueryBase.cs
with MIT License
from 0x0ade
with MIT License
from 0x0ade
protected virtual void Dispose(bool flag) {
Destroy();
_completedCallResult?.Cancel();
(_completedCallResult as IDisposable)?.Dispose();
_completedCallResult = null;
}
19
Source : DisposableLazy.cs
with GNU Lesser General Public License v3.0
from 0xC0000054
with GNU Lesser General Public License v3.0
from 0xC0000054
public void Dispose()
{
if (this.IsValueCreated)
{
this.Value.Dispose();
}
}
19
Source : DisposableUtil.cs
with GNU Lesser General Public License v3.0
from 0xC0000054
with GNU Lesser General Public License v3.0
from 0xC0000054
public static void Free<TDisposable>(ref TDisposable disposable) where TDisposable : clreplaced, IDisposable
{
if (disposable != null)
{
disposable.Dispose();
disposable = null;
}
}
19
Source : Program.cs
with MIT License
from 0xDivyanshu
with MIT License
from 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
Source : Helper.cs
with MIT License
from 0xDivyanshu
with MIT License
from 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
Source : Dumper.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public void Dispose()
{
driveStream?.Dispose();
((IDisposable)Decrypter)?.Dispose();
Cts?.Dispose();
}
19
Source : MainPage.xaml.cs
with MIT License
from 1iveowl
with MIT License
from 1iveowl
private void Stop_OnClick(object sender, RoutedEventArgs e)
{
_disposable.Dispose();
}
19
Source : HttpStreamParser.cs
with MIT License
from 1iveowl
with MIT License
from 1iveowl
public void Dispose()
{
_disposableParserCompletion?.Dispose();
_parser?.Dispose();
}
19
Source : AreaForm.cs
with MIT License
from 1CM69
with MIT License
from 1CM69
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
this.components.Dispose();
base.Dispose(disposing);
}
19
Source : ObjectPool.cs
with MIT License
from 2881099
with MIT License
from 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
Source : ObjectPool.cs
with MIT License
from 2881099
with MIT License
from 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
Source : Object.cs
with MIT License
from 2881099
with MIT License
from 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
Source : Store.cs
with MIT License
from 71
with MIT License
from 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
Source : IoCBindData.cs
with MIT License
from 7Bytes-Studio
with MIT License
from 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
Source : ControlDisplay.cs
with GNU Lesser General Public License v3.0
from 9and3
with GNU Lesser General Public License v3.0
from 9and3
[DebuggerNonUserCode]
protected override void Dispose(bool disposing) {
try {
if (disposing && this.components != null) {
this.components.Dispose();
}
} finally {
base.Dispose(disposing);
}
}
19
Source : GH_Cloud.cs
with GNU Lesser General Public License v3.0
from 9and3
with GNU Lesser General Public License v3.0
from 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
Source : JobFactory.cs
with Apache License 2.0
from 91270
with Apache License 2.0
from 91270
public void ReturnJob(IJob job)
{
var disposable = job as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
19
Source : Param_Cloud.cs
with GNU Lesser General Public License v3.0
from 9and3
with GNU Lesser General Public License v3.0
from 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
Source : ClientForm1.Designer.cs
with MIT License
from a11s
with MIT License
from a11s
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
19
Source : SerializationContext.cs
with MIT License
from a1q123456
with MIT License
from a1q123456
public void Dispose()
{
if (_disposeBuffer)
{
((IDisposable)Buffer).Dispose();
}
}
19
Source : ChunkStreamContext.cs
with MIT License
from a1q123456
with MIT License
from a1q123456
public void Dispose()
{
((IDisposable)_rtmpSession).Dispose();
}
19
Source : NetConnection.cs
with MIT License
from a1q123456
with MIT License
from 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
Source : RtmpSession.cs
with MIT License
from a1q123456
with MIT License
from 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
Source : WebSocketSession.cs
with MIT License
from a1q123456
with MIT License
from a1q123456
internal void HandleClose()
{
if (_controller is IDisposable disp)
{
disp.Dispose();
}
_controller = null;
}
19
Source : Program.cs
with MIT License
from ab4d
with MIT License
from ab4d
public static void Dispose(IDisposable disposable)
{
if(disposable != null)
disposable.Dispose();
}
19
Source : WeatherMonitor.cs
with GNU General Public License v3.0
from abishekaditya
with GNU General Public License v3.0
from abishekaditya
public void Unsubscribe()
{
_cancellation.Dispose();
}
19
Source : CollectionsExtensions.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from 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
Source : CollectionsExtensions.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from 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
Source : VitalSignsMonitorView.xaml.cs
with MIT License
from ABTSoftware
with MIT License
from ABTSoftware
private void OnUnloaded(object sender, RoutedEventArgs e)
{
_dataSubscription.Dispose();
}
19
Source : YAxisSameZeroLine.xaml.cs
with MIT License
from ABTSoftware
with MIT License
from ABTSoftware
public void Dispose()
{
Subscription?.Dispose();
}
19
Source : FrmCaptcha.Designer.cs
with MIT License
from ACBrNet
with MIT License
from ACBrNet
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
19
Source : RemoteModuleTypeLoader.cs
with MIT License
from Accelerider
with MIT License
from Accelerider
protected virtual void Dispose(bool disposing)
{
var disposableResolver = _replacedemblyResolver as IDisposable;
disposableResolver?.Dispose();
}
19
Source : FileDownloaderManager.cs
with MIT License
from Accelerider
with MIT License
from 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
Source : App.xaml.cs
with MIT License
from Accelerider
with MIT License
from 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
Source : SixCloudUser.cs
with MIT License
from Accelerider
with MIT License
from 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
Source : FileDownloader.cs
with MIT License
from Accelerider
with MIT License
from Accelerider
protected virtual void Dispose(bool disposing)
{
if (Status == TransferStatus.Disposed) return;
if (disposing)
{
_cancellationTokenSource?.Cancel();
_disposable?.Dispose();
}
}
19
Source : HostContext.cs
with MIT License
from actions
with MIT License
from 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
Source : HasTempFolder.cs
with MIT License
from action-bi-toolkit
with MIT License
from action-bi-toolkit
public virtual void Dispose()
{
(TestFolder as IDisposable)?.Dispose();
}
19
Source : ExpressionNode.cs
with MIT License
from actions
with MIT License
from 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
Source : VssConnection.cs
with MIT License
from actions
with MIT License
from 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
Source : FileLoggerProvider.cs
with MIT License
from adams85
with MIT License
from 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
Source : Arrays.cs
with MIT License
from adamped
with MIT License
from adamped
public static void DeleteArray<T>(T[] array) where T: System.IDisposable
{
foreach (T element in array)
{
if (element != null)
element.Dispose();
}
}
19
Source : BaseManager.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
protected virtual void Dispose(bool disposing)
{
if (_disposed) return;
if (disposing)
{
Store.Dispose();
}
Store = null;
_disposed = true;
}
19
Source : CrmDbContext.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
protected virtual void Dispose(bool disposing)
{
if (DisposeContext && disposing)
{
var service = Service as IDisposable;
if (service != null)
{
service.Dispose();
Service = null;
}
}
}
19
Source : TreeNode.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public void Dispose()
{
if (!(Value is IDisposable)) return;
foreach (var node in Children.Cast<TreeNode<T>>())
{
node.Dispose();
}
(Value as IDisposable).Dispose();
}
19
Source : HttpSingleton.cs
with MIT License
from Adoxio
with MIT License
from 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
Source : DeploymentService.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public virtual void Dispose()
{
var service = _service.Value as IDisposable;
if (service != null)
{
service.Dispose();
}
}
19
Source : CrmOrganizationServiceContext.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
protected override void Dispose(bool disposing)
{
if (disposing && _shouldDisposeService)
{
var service = _service as IDisposable;
if (service != null)
{
service.Dispose();
}
}
base.Dispose(disposing);
}
19
Source : Parallel.cs
with MIT License
from adrenak
with MIT License
from 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
}
See More Examples