当前位置: 首页>>代码示例>>C#>>正文


C# IDisposable.Dispose方法代码示例

本文整理汇总了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;
        }
开发者ID:akarnokd,项目名称:RxReactiveStreamsCSharp,代码行数:28,代码来源:CompositeDisposable.cs

示例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();
        }
开发者ID:40a,项目名称:Tx,代码行数:33,代码来源:Program.cs

示例3: Dispose

 public static void Dispose(IDisposable disposable)
 {
     if (disposable != null)
     {
         disposable.Dispose();
     }
 }
开发者ID:katasource,项目名称:shironet,代码行数:7,代码来源:LifecycleUtils.cs

示例4: Close

			private static void Close(IDisposable counter)
			{
				if (null != counter)
				{
					counter.Dispose();
				}
			}
开发者ID:Galigator,项目名称:db4o,代码行数:7,代码来源:QueryMonitoringSupport.cs

示例5: p_StreamDispose

 // ::
 public static void p_StreamDispose(IDisposable ido)
 {
     if (ido != null)
     {
         ido.Dispose();
     }
 }
开发者ID:Hobis,项目名称:HB_VisualBasic,代码行数:8,代码来源:Program.cs

示例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
            }
        }
开发者ID:BO45,项目名称:NzbDrone,代码行数:25,代码来源:Disposer.cs

示例7: DisposeIt

 static void DisposeIt(IDisposable d)
 {
     if (d != null)
       {
     d.Dispose ();
       }
 }
开发者ID:mrange,项目名称:funbasic,代码行数:7,代码来源:D2D.cs

示例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(); } });
        }
开发者ID:nuub666,项目名称:framework,代码行数:7,代码来源:Disposable.cs

示例9: DisposeIt

 /// <summary>
 /// 释放对象
 /// </summary>
 /// <param name="disposeObject"></param>
 protected void DisposeIt(IDisposable disposeObject)
 {
     if (disposeObject != null)
     {
         disposeObject.Dispose();
     }
 }
开发者ID:diamondiamon,项目名称:WeikerenUtility,代码行数:11,代码来源:DisposableObject.cs

示例10: DisposePage

        private static void DisposePage(IDisposable page)
        {
            if (page == null)
                return;

            page.Dispose();
        }
开发者ID:modulexcite,项目名称:MvvmNano,代码行数:7,代码来源:MvvmNanoNavigationPage.cs

示例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;
		}
开发者ID:guadalinex-archive,项目名称:guadalinex-v6,代码行数:26,代码来源:FileDatabase.cs

示例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);
        }
开发者ID:GaneshBachhao,项目名称:SignalR,代码行数:32,代码来源:ControllerHub.cs

示例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();
        }
开发者ID:ozzimpact,项目名称:helmet.net,代码行数:28,代码来源:CrossDomainMiddlewareTest.cs

示例14: Dispose

 private void Dispose(IDisposable disposable)
 {
     if (disposable != null)
     {
         disposable.Dispose();
     }
 }
开发者ID:allansson,项目名称:pact-net,代码行数:7,代码来源:NancyHttpHost.cs

示例15: RemoveAndDispose

        public static void RemoveAndDispose(this MultipleDisposable self, IDisposable target)
        {
            if (target == null)
                return;

            self.Remove(target);
            target.Dispose();
        }
开发者ID:YoshihiroIto,项目名称:Anne,代码行数:8,代码来源:MultipleDisposableExtensions.cs


注:本文中的IDisposable.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。