本文整理汇总了C#中IDisposable.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IDisposable.Dispose方法的具体用法?C# IDisposable.Dispose怎么用?C# IDisposable.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDisposable
的用法示例。
在下文中一共展示了IDisposable.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public bool Add(IDisposable d)
{
if (disposed)
{
d.Dispose();
return false;
}
lock (this)
{
if (!disposed)
{
var set = this.set;
if (set == null)
{
set = new LinkedList<IDisposable>();
this.set = set;
}
set.AddLast(d);
return true;
}
}
d.Dispose();
return false;
}
示例2: ListenWithQuery
static void ListenWithQuery()
{
Console.WriteLine("----- Listening with Tx-Playback and Rx query -----");
_playback = new Playback();
_playback.AddRealTimeSession(Baseline.SessionName);
var received = _playback.GetObservable<KNetEvt_RecvIPV4>();
var x = from window in received.Window(TimeSpan.FromSeconds(1), _playback.Scheduler)
from stats in
(from packet in window
group packet by packet.daddr into g
from total in g.Sum(p => p.size)
select new
{
address = new IPAddress(g.Key).ToString(),
received = total
})
.ToList()
select stats.OrderBy(s => s.address);
_subscription = x.Subscribe(v =>
{
Console.WriteLine("--- {0} ---", DateTime.Now);
foreach (var s in v)
Console.WriteLine("{0, -15} {1,-10:n0} ", s.address, s.received);
Console.WriteLine();
});
_playback.Start();
Console.ReadLine();
_subscription.Dispose();
}
示例3: Dispose
public static void Dispose(IDisposable disposable)
{
if (disposable != null)
{
disposable.Dispose();
}
}
示例4: Close
private static void Close(IDisposable counter)
{
if (null != counter)
{
counter.Dispose();
}
}
示例5: p_StreamDispose
// ::
public static void p_StreamDispose(IDisposable ido)
{
if (ido != null)
{
ido.Dispose();
}
}
示例6: Set
public void Set(IDisposable disposable)
{
if (disposable == null)
{
throw new ArgumentNullException("disposable");
}
object originalFieldValue = Interlocked.CompareExchange(ref _disposable, disposable, null);
if (originalFieldValue == null)
{
// this is the first call to Set() and Dispose() hasn't yet been called; do nothing
}
else if (originalFieldValue == _disposedSentinel)
{
// Dispose() has already been called, so we need to dispose of the object that was just added
disposable.Dispose();
}
else
{
#if !NET35 && !SILVERLIGHT && !NETFX_CORE
// Set has been called multiple times, fail
Debug.Fail("Multiple calls to Disposer.Set(IDisposable) without calling Disposer.Dispose()");
#endif
}
}
示例7: DisposeIt
static void DisposeIt(IDisposable d)
{
if (d != null)
{
d.Dispose ();
}
}
示例8: Combine
public static IDisposable Combine(IDisposable first, IDisposable second)
{
if (first == null || second == null)
return first ?? second;
return new Disposable(() => { try { first.Dispose(); } finally { second.Dispose(); } });
}
示例9: DisposeIt
/// <summary>
/// 释放对象
/// </summary>
/// <param name="disposeObject"></param>
protected void DisposeIt(IDisposable disposeObject)
{
if (disposeObject != null)
{
disposeObject.Dispose();
}
}
示例10: DisposePage
private static void DisposePage(IDisposable page)
{
if (page == null)
return;
page.Dispose();
}
示例11: BeginTransaction
public bool BeginTransaction ()
{
if (inTransaction)
throw new InvalidOperationException ("Already in a transaction");
transactionLock = LockWrite ();
try {
updatingLock = new FileStream (UpdateDatabaseLockFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
} catch (IOException) {
// The database is already being updated. Can't do anything for now.
return false;
} finally {
transactionLock.Dispose ();
}
// Delete .new files that could have been left by an aborted database update
transactionLock = LockRead ();
CleanDirectory (rootDirectory);
inTransaction = true;
foldersToUpdate = new Hashtable ();
deletedFiles = new Hashtable ();
deletedDirs = new Hashtable ();
return true;
}
示例12: Run
private static void Run()
{
if (Arguments.NumClients > 1)
{
AppHost = WebApp.Start<Startup>(Arguments.ControllerUrl);
if (!WaitForClientsToConnect())
{
SignalPhaseChange(ControllerEvents.Abort);
for (int attempts = 0; (ClientsConnected > 0) && (attempts < CrankArguments.ConnectionPollAttempts); attempts++)
{
Thread.Sleep(CrankArguments.ConnectionPollIntervalMS);
}
AppHost.Dispose();
return;
}
}
RunConnect();
RunSend();
RunDisconnect();
WaitForLastSamples();
if (AppHost != null)
{
AppHost.Dispose();
}
FlushLog(force:true);
}
示例13: ExpectPolicy
public async void ExpectPolicy()
{
var address = GetRandomAddress();
_server = WebApp.Start(address, appBuilder =>
{
appBuilder.Use<CrossDomainMiddleware>(new CrossDomainOptions()
{
CaseSensitive = true
});
appBuilder.UseWebApi(_config);
});
_client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, address + "/crossdomain.xml");
var httpResponseMessage = await _client.SendAsync(request);
HttpContent httpContent = httpResponseMessage.Content;
IEnumerable<string> values;
httpContent.Headers.TryGetValues("Content-Type", out values);
var assert = values as string[] ?? values.ToArray();
assert.Should().NotBeNull(Policy);
assert.Should().NotBeNull("text/x-cross-domain-policy");
_server.Dispose();
}
示例14: Dispose
private void Dispose(IDisposable disposable)
{
if (disposable != null)
{
disposable.Dispose();
}
}
示例15: RemoveAndDispose
public static void RemoveAndDispose(this MultipleDisposable self, IDisposable target)
{
if (target == null)
return;
self.Remove(target);
target.Dispose();
}