本文整理汇总了C#中IDisposable类的典型用法代码示例。如果您正苦于以下问题:C# IDisposable类的具体用法?C# IDisposable怎么用?C# IDisposable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDisposable类属于命名空间,在下文中一共展示了IDisposable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public void Add(IDisposable component)
{
if (component != null)
{
this.components.Add(component);
}
}
示例2: ItemAutoSubscription
/// <summary>
/// Initializes a new instance of the <see cref = "ItemAutoSubscription" /> class.
/// </summary>
/// <param name = "item">
/// The subscribed item.
/// </param>
/// <param name = "itemPosition">
/// The item position.
/// </param>
/// <param name = "itemRegion">
/// The item Region.
/// </param>
/// <param name = "subscription">
/// The subscription.
/// </param>
public ItemAutoSubscription(Item item, Vector itemPosition, Region itemRegion, IDisposable subscription)
{
this.ItemPosition = itemPosition;
this.item = item;
this.subscription = subscription;
this.WorldRegion = itemRegion;
}
示例3: SetVideoCodecToken
/// <summary>
/// sets the codec token to be used for video compression
/// </summary>
public void SetVideoCodecToken(IDisposable token)
{
if (token is CodecToken)
currVideoCodecToken = (CodecToken)token;
else
throw new ArgumentException("AviWriter only takes its own Codec Tokens!");
}
示例4: Configure
private void Configure(AzureServiceBusOwinServiceConfiguration config, Action<IAppBuilder> startup)
{
if (startup == null)
{
throw new ArgumentNullException("startup");
}
var options = new StartOptions();
if (string.IsNullOrWhiteSpace(options.AppStartup))
{
// Populate AppStartup for use in host.AppName
options.AppStartup = startup.Method.ReflectedType.FullName;
}
var testServerFactory = new AzureServiceBusOwinServerFactory(config);
var services = ServicesFactory.Create();
var engine = services.GetService<IHostingEngine>();
var context = new StartContext(options)
{
ServerFactory = new ServerFactoryAdapter(testServerFactory),
Startup = startup
};
_started = engine.Start(context);
_next = testServerFactory.Invoke;
}
示例5: LightningQueuesChannel
public LightningQueuesChannel(Uri address, string queueName, Queue queueManager)
{
Address = address;
_queueName = queueName;
_queueManager = queueManager;
_disposable = Disposable.Empty;
}
示例6: Open
public static void Open(params string[] hostUrls)
{
try
{
if (_CloseOWin == null)
{
// Start OWIN host
StartOptions so = new StartOptions();
foreach (string s in hostUrls)
{
so.Urls.Add(s);
}
_CloseOWin = WebApp.Start<SNStartup>(so);
}
}
catch (Exception ex)
{
if (ex.InnerException is System.Net.HttpListenerException)
{
throw new Exception("监听IP有错误");
}
if (_CloseOWin != null)
{
_CloseOWin.Dispose();//必须
_CloseOWin = null;//必须
}
throw;
}
}
示例7: NodeViewModel
public NodeViewModel(Node node, Vector location, IControlTypesResolver controlTypesResolver)
{
Node = node;
Title = node.Title;
Location = new CanvasPoint(location);
ControlTypesResolver = controlTypesResolver;
foreach (var pin in node.InputPins)
{
AddInputPin(pin);
}
foreach (var pin in node.OutputPins)
{
AddOutputPin(pin);
}
node.Processed += OnNodeProcessed;
node.PinsChanged += OnNodePinsChanged;
_disposable = Disposable.Create(() =>
{
node.PinsChanged -= OnNodePinsChanged;
node.Processed -= OnNodeProcessed;
});
}
示例8: MDRefactoringScript
public MDRefactoringScript (MDRefactoringContext context, CSharpFormattingOptions formattingOptions) : base(context.TextEditor.Document, formattingOptions, context.TextEditor.CreateNRefactoryTextEditorOptions ())
{
this.context = context;
undoGroup = this.context.TextEditor.OpenUndoGroup ();
this.startVersion = this.context.TextEditor.Version;
}
示例9: Dispose
public void Dispose()
{
if(_storeSubscription == null)
return;
_storeSubscription.Dispose();
_storeSubscription = null;
_pluginChannel.Do(x => x.Value.Dispose());
_pluginChannel.Clear();
_pluginChannel = null;
_pluginServer.Do(x => x.Value.Dispose());
_pluginServer.Clear();
_pluginServer = null;
_pluginGlobal.Do(x => x.Value.Dispose());
_pluginGlobal.Clear();
_pluginGlobal = null;
_channel.Do(x => x.Value.Dispose());
_channel.Clear();
_channel = null;
_server.Do(x => x.Value.Dispose());
_server.Clear();
_server = null;
_global.Dispose();
_global = null;
}
示例10: VirtualListVewModel
public VirtualListVewModel(SynchronizationContext bindingContext, DataService service)
{
_virtualRequest = new BehaviorSubject<VirtualRequest>(new VirtualRequest(0,10));
Items = new BindingList<Poco>();
var sharedDataSource = service
.DataStream
.Do(x => Trace.WriteLine($"Service -> {x}"))
.ToObservableChangeSet()
.Publish();
var binding = sharedDataSource
.Virtualise(_virtualRequest)
.ObserveOn(bindingContext)
.Bind(Items)
.Subscribe();
//the problem was because Virtualise should fire a noticiation if count changes, but it does not [BUG]
//Therefore take the total count from the underlying data NB: Count is DD.Count() not Observable.Count()
Count = sharedDataSource.Count().DistinctUntilChanged();
Count.Subscribe(x => Trace.WriteLine($"Count = {x}"));
var connection = sharedDataSource.Connect();
_disposables = new CompositeDisposable(binding, connection);
}
示例11: Connect
public void Connect(IEventStream stream)
{
subscription = stream.Of<IEventPattern<IDevice, ISensed>>().Subscribe(sensed =>
{
var type = topicRegistry.Find(sensed.EventArgs.Topic);
switch (type)
{
case TopicType.Boolean:
stream.Push(sensed.Sender, Impulse.Create(sensed.EventArgs.Topic, Payload.ToBoolean(sensed.EventArgs.Payload), clock.Now));
break;
case TopicType.Number:
stream.Push(sensed.Sender, Impulse.Create(sensed.EventArgs.Topic, Payload.ToNumber(sensed.EventArgs.Payload), clock.Now));
break;
case TopicType.String:
stream.Push(sensed.Sender, Impulse.Create(sensed.EventArgs.Topic, Payload.ToString(sensed.EventArgs.Payload), clock.Now));
break;
case TopicType.Void:
stream.Push(sensed.Sender, Impulse.Create(sensed.EventArgs.Topic, Unit.Default, clock.Now));
break;
case TopicType.Unknown:
default:
// TODO: throw? Report?
break;
}
});
}
示例12: 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;
}
示例13: AggregationViewModel
public AggregationViewModel()
{
var sourceList = new SourceList<AggregationItem>();
sourceList.AddRange(Enumerable.Range(1, 15).Select(i => new AggregationItem(i)));
//Load items to display to user and allow them to include items or not
var listLoader = sourceList.Connect()
.Sort(SortExpressionComparer<AggregationItem>.Ascending(vm => vm.Number))
.ObserveOnDispatcher()
.Bind(out _items)
.Subscribe();
// share the connection because we are doing multiple aggregations
var aggregatable = sourceList.Connect()
.FilterOnProperty(vm => vm.IncludeInTotal, vm => vm.IncludeInTotal)
.Publish();
//Do a custom aggregation (ToCollection() produces a readonly collection of underlying data)
var sumOfOddNumbers = aggregatable.ToCollection()
.Select(collection => collection.Where(i => i.Number%2 == 1).Select(ai => ai.Number).Sum())
.Subscribe(sum => SumOfOddNumbers = sum);
_cleanUp = new CompositeDisposable(sourceList,
listLoader,
aggregatable.Count().Subscribe(count => Count = count),
aggregatable.Sum(ai => ai.Number).Subscribe(sum => Sum = sum),
aggregatable.Avg(ai => ai.Number).Subscribe(average => Avg = Math.Round(average,2)),
aggregatable.Minimum(ai => ai.Number).Subscribe(max => Max = max),
aggregatable.Maximum(ai => ai.Number).Subscribe(min => Min = min),
aggregatable.StdDev(ai => ai.Number).Subscribe(std => StdDev = Math.Round(std, 2)),
sumOfOddNumbers,
aggregatable.Connect());
}
示例14: SPOEmulationContext
/// <summary>
/// Initializes a new instance of the <see cref="SPOEmulationContext"/> class.
/// </summary>
/// <param name="isolationLevel">The level.</param>
/// <param name="connectionInformation">The connection informations for the target web.</param>
public SPOEmulationContext(IsolationLevel isolationLevel, ConnectionInformation connectionInformation)
{
this._isolationLevel = isolationLevel;
switch (isolationLevel)
{
case IsolationLevel.Fake:
// create shim context
_shimsContext = ShimsContext.Create();
// initialize all simulated types
_clientContext = InitializeSimulatedAPI(connectionInformation.Url);
break;
case IsolationLevel.Integration:
// create shim context
_shimsContext = ShimsContext.Create();
Connect(connectionInformation);
break;
case IsolationLevel.None:
Connect(connectionInformation);
break;
default:
throw new InvalidOperationException();
}
}
示例15: Start
// global instances that keep controller and windows service alive
public void Start(QueueMessageManager manager = null)
{
if (manager == null)
manager = new QueueMessageManagerSql();
LogManager.Current.LogInfo("Start called");
var config = QueueMessageManagerConfiguration.Current;
Controller = new QueueController()
{
ConnectionString = config.ConnectionString,
QueueName = config.QueueName,
WaitInterval = config.WaitInterval,
ThreadCount = config.ControllerThreads
};
LogManager.Current.LogInfo("Controller created.");
// asynchronously start the SignalR hub
SignalR = WebApplication.Start<SignalRStartup>("http://*:8080/");
// *** Spin up n Number of threads to process requests
Controller.StartProcessingAsync();
LogManager.Current.LogInfo(String.Format("QueueManager Controller Started with {0} threads.",
Controller.ThreadCount));
// Set static instances so that these 'services' stick around
GlobalService.Controller = Controller;
GlobalService.Service = this;
}