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


C# Timer.Start方法代码示例

本文整理汇总了C#中System.Threading.Timer.Start方法的典型用法代码示例。如果您正苦于以下问题:C# Timer.Start方法的具体用法?C# Timer.Start怎么用?C# Timer.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Timer的用法示例。


在下文中一共展示了Timer.Start方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoesntRunIfTimerIsStartedAgain

 public void DoesntRunIfTimerIsStartedAgain()
 {
     var startTime = new DateTime();
     var autoResetEvent = new AutoResetEvent(false);
     var timer = new Timer<string>(a => {
                                       ThreadAssertion(DateTime.Now.Subtract(startTime), new GreaterThanOrEqualConstraint(TimeSpan.FromSeconds(.9)));
                                       autoResetEvent.Set();
                                   });
     startTime = DateTime.Now;
     timer.Start(.5, "");
     Thread.Sleep(TimeSpan.FromSeconds(.4));
     timer.Start(.5, "");
     Assert.AreEqual(true, autoResetEvent.WaitOne(TimeSpan.FromSeconds(10), false));
 }
开发者ID:srushti,项目名称:azazel,代码行数:14,代码来源:TimerTest.cs

示例2: AutoSave

 public AutoSave(Delegate notify, double saveTime, Game1 game)
 {
     this.notify = notify;
     timer = new Timer(saveTime, game);
     timer.Elapsed = SaveDue;
     timer.Start();
 }
开发者ID:jbornemann,项目名称:Ascian,代码行数:7,代码来源:AutoSave.cs

示例3: AdoNetOnly

        public void AdoNetOnly()
        {
            for (int n = 2; n < 4000; n *= 2)
            {
                Simple[] simples = new Simple[n];
                for (int i = 0; i < n; i++)
                {
                    simples[i] = new Simple();
                    simples[i].Init();
                    simples[i].Count = i;
                    simples[i].Id = i;
                }

                //Now do timings
                Timer timer = new Timer();

                IDbConnection _connection = sqlMap.DataSource.DbProvider.CreateConnection();
                _connection.ConnectionString = sqlMap.DataSource.ConnectionString;

                _connection.Open();

                timer.Start();
                DirectAdoNet(_connection, simples, n, "j1");
                timer.Stop();
                double adonet = 1000000 * (timer.Duration / (double)n);
                _connection.Close();

                _connection.Open();
                timer.Start();
                DirectAdoNet(_connection, simples, n, "j2");
                timer.Stop();
                adonet += 1000000 * (timer.Duration / (double)n);
                _connection.Close();

                _connection.Open();
                timer.Start();
                DirectAdoNet(_connection, simples, n, "j2");
                timer.Stop();
                adonet += 1000000 * (timer.Duration / (double)n);
                _connection.Close();

                System.Console.Out.WriteLine("Objects: " + n + " Direct ADO.NET: " + adonet.ToString("F3"));
            }
            System.GC.Collect();
        }
开发者ID:hejiquan,项目名称:iBATIS_2010,代码行数:45,代码来源:PerformanceTest.cs

示例4: RunsAfterHalfASecond

 public void RunsAfterHalfASecond()
 {
     var startTime = new DateTime();
     var autoResetEvent = new AutoResetEvent(false);
     var timer = new Timer<string>(a => {
                                       ThreadAssertion(DateTime.Now.Subtract(startTime), new GreaterThanConstraint(TimeSpan.FromSeconds(.5)));
                                       autoResetEvent.Set();
                                   });
     startTime = DateTime.Now;
     timer.Start(.5, "");
     Assert.AreEqual(true, autoResetEvent.WaitOne(TimeSpan.FromSeconds(10), false));
 }
开发者ID:srushti,项目名称:azazel,代码行数:12,代码来源:TimerTest.cs

示例5: Start

        public override void Start(MessageTypes types)
        {
            base.Start (types);

            Timer timer = new Timer (100);
            timer = new Timer (100);
            timer.TimesUp += OnDeliveryTimer;
            timer.Start();
            this.deliveryTimer = timer;
        }
开发者ID:morpheusllc,项目名称:Tempest,代码行数:10,代码来源:UdpConnectionProvider.cs

示例6: ConnectAsync

		public async Task<ClientConnectionResult> ConnectAsync (Target target, MessageTypes messageTypes)
		{
			if (target == null)
				throw new ArgumentNullException ("target");
			if (!Enum.IsDefined (typeof (MessageTypes), messageTypes))
				throw new ArgumentOutOfRangeException ("messageTypes");

			IPEndPoint = await target.ToIPEndPointAsync().ConfigureAwait (false);
			if (IPEndPoint.AddressFamily != AddressFamily.InterNetwork && IPEndPoint.AddressFamily != AddressFamily.InterNetworkV6)
				throw new ArgumentException ("Unsupported endpoint AddressFamily");

			var ntcs = new TaskCompletionSource<ClientConnectionResult>();

			ThreadPool.QueueUserWorkItem (s =>
			{
				Trace.WriteLineIf (NTrace.TraceVerbose, String.Format ("Waiting for pending ({0}) async..", this.pendingAsync));

				while (this.pendingAsync > 0 || Interlocked.CompareExchange (ref this.connectTcs, ntcs, null) != null)
					Thread.Sleep (0);

				int p = Interlocked.Increment (ref this.pendingAsync);
				Trace.WriteLineIf (NTrace.TraceVerbose, String.Format ("Increment pending: {0}", p));

				this.serializer = new ClientMessageSerializer (this, this.originalProtocols);

				IEnumerable<string> hashAlgs = null;
				if (this.localCrypto != null)
					hashAlgs = this.localCrypto.SupportedHashAlgs;

				Start (messageTypes);

				this.socket = this.listener.GetSocket (IPEndPoint);

				Timer dtimer = new Timer (100);
				dtimer.TimesUp += OnDeliveryTimer;
				dtimer.Start();
				this.deliveryTimer = dtimer;

				Timer t = new Timer (30000);
				Timer previousTimer = Interlocked.Exchange (ref this.connectTimer, t);
				if (previousTimer != null)
					previousTimer.Dispose();

				t.AutoReset = false;
				t.TimesUp += (sender, args) =>
				{
					var tcs = this.connectTcs;
					if (tcs != null)
						tcs.TrySetResult (new ClientConnectionResult (ConnectionResult.ConnectionFailed, null));

					Disconnect (ConnectionResult.ConnectionFailed);
					t.Dispose();
				};
				t.Start();

				RemoteTarget = target;
				SendAsync (new ConnectMessage
				{
					Protocols = Protocols,
					SignatureHashAlgorithms = hashAlgs
				}).ContinueWith (st =>
				{
					int pa = Interlocked.Decrement (ref this.pendingAsync);
					Trace.WriteLineIf (NTrace.TraceVerbose, String.Format ("Decrement pending: {0}", pa));
				});
			});

			return await ntcs.Task.ConfigureAwait (false);
		}
开发者ID:morpheusllc,项目名称:Tempest,代码行数:69,代码来源:UdpClientConnection.cs

示例7: IbatisOnly

        public void IbatisOnly()
        {
            for (int n = 2; n < 4000; n *= 2)
            {
                Simple[] simples = new Simple[n];
                object[] ids = new object[n];
                for (int i = 0; i < n; i++)
                {
                    simples[i] = new Simple();
                    simples[i].Init();
                    simples[i].Count = i;
                    simples[i].Id = i;
                }

                //Now do timings
                Timer timer = new Timer();
                GC.Collect();
                GC.WaitForPendingFinalizers();

                sqlMap.OpenConnection();
                timer.Start();
                Ibatis(simples, n, "h1");
                timer.Stop();
                double ibatis = 1000000 * (timer.Duration / (double)n);
                sqlMap.CloseConnection();

                sqlMap.OpenConnection();
                timer.Start();
                Ibatis(simples, n, "h2");
                timer.Stop();
                ibatis += 1000000 * (timer.Duration / (double)n);
                sqlMap.CloseConnection();

                sqlMap.OpenConnection();
                timer.Start();
                Ibatis(simples, n, "h2");
                timer.Stop();
                ibatis += 1000000 * (timer.Duration / (double)n);
                sqlMap.CloseConnection();

                System.Console.WriteLine("Objects: " + n + " - iBATIS DataMapper: " + ibatis.ToString("F3"));
            }
            System.GC.Collect();
        }
开发者ID:hejiquan,项目名称:iBATIS_2010,代码行数:44,代码来源:PerformanceTest.cs

示例8: Simultaneous

        public void Simultaneous()
        {
            double ibatis = 0;
            double adonet = 0;

            IDbConnection _connection = sqlMap.DataSource.DbProvider.CreateConnection();
            _connection.ConnectionString = sqlMap.DataSource.ConnectionString;

            for (int n = 2; n < 4000; n *= 2)
            {
                Simple[] simples = new Simple[n];
                for (int i = 0; i < n; i++)
                {
                    simples[i] = new Simple();
                    simples[i].Init();
                    simples[i].Count = i;
                    simples[i].Id = i;
                }

                sqlMap.OpenConnection();
                Ibatis(simples, n, "h0");
                sqlMap.CloseConnection();

                _connection.Open();
                DirectAdoNet(_connection, simples, n, "j0");
                _connection.Close();

                sqlMap.OpenConnection();
                Ibatis(simples, n, "h0");
                sqlMap.CloseConnection();

                _connection.Open();
                DirectAdoNet(_connection, simples, n, "j0");
                _connection.Close();

                //Now do timings
                Timer timer = new Timer();

                GC.Collect();
                GC.WaitForPendingFinalizers();

                sqlMap.OpenConnection();
                timer.Start();
                Ibatis(simples, n, "h1");
                timer.Stop();
                ibatis = 1000000 * (timer.Duration / (double)n);
                sqlMap.CloseConnection();

                _connection.Open();
                timer.Start();
                DirectAdoNet(_connection, simples, n, "j1");
                timer.Stop();
                adonet = 1000000 * (timer.Duration / (double)n);
                _connection.Close();

                sqlMap.OpenConnection();
                timer.Start();
                Ibatis(simples, n, "h2");
                timer.Stop();
                ibatis += 1000000 * (timer.Duration / (double)n);
                sqlMap.CloseConnection();

                _connection.Open();
                timer.Start();
                DirectAdoNet(_connection, simples, n, "j2");
                timer.Stop();
                adonet += 1000000 * (timer.Duration / (double)n);
                _connection.Close();

                sqlMap.OpenConnection();
                timer.Start();
                Ibatis(simples, n, "h2");
                timer.Stop();
                ibatis += 1000000 * (timer.Duration / (double)n);
                sqlMap.CloseConnection();

                _connection.Open();
                timer.Start();
                DirectAdoNet(_connection, simples, n, "j2");
                timer.Stop();
                adonet += 1000000 * (timer.Duration / (double)n);
                _connection.Close();
                System.Console.Out.WriteLine("Objects " + n + " iBATIS DataMapper : " + ibatis.ToString("F3") + " / Direct ADO.NET: " + adonet.ToString("F3") + " Ratio: " + ((ibatis / adonet)).ToString("F3"));
            }

            System.GC.Collect();
        }
开发者ID:hejiquan,项目名称:iBATIS_2010,代码行数:87,代码来源:PerformanceTest.cs

示例9: Many

        public void Many()
        {
            double ibatis = 0;
            double adonet = 0;

            for (int n = 0; n < 5; n++)
            {
                Simple[] simples = new Simple[n];
                for (int i = 0; i < n; i++)
                {
                    simples[i] = new Simple();
                    simples[i].Init();
                    simples[i].Count = i;
                    simples[i].Id = i;
                }

                sqlMap.OpenConnection();
                Ibatis(simples, n, "h0");
                sqlMap.CloseConnection();

                IDbConnection _connection = sqlMap.DataSource.DbProvider.CreateConnection();
                _connection.ConnectionString = sqlMap.DataSource.ConnectionString;

                _connection.Open();
                DirectAdoNet(_connection, simples, n, "j0");
                _connection.Close();

                sqlMap.OpenConnection();
                Ibatis(simples, n, "h0");
                sqlMap.CloseConnection();

                _connection.Open();
                DirectAdoNet(_connection, simples, n, "j0");
                _connection.Close();

                // now do timings

                int loops = 30;
                Timer timer = new Timer();

                for (int runIndex = 1; runIndex < 4; runIndex++)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    timer.Start();
                    for (int i = 0; i < loops; i++)
                    {
                        sqlMap.OpenConnection();
                        Ibatis(simples, n, "h" + runIndex.ToString());
                         sqlMap.CloseConnection();
                    }
                    timer.Stop();
                    ibatis += 1000000 * (timer.Duration / (double)loops);

                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    timer.Start();
                    for (int i = 0; i < loops; i++)
                    {
                        _connection.Open();
                        DirectAdoNet(_connection, simples, n, "j" + runIndex.ToString());
                        _connection.Close();
                    }
                    timer.Stop();
                    adonet += 1000000 * (timer.Duration / (double)loops);

                }
            }
            System.Console.Out.WriteLine("iBatis DataMapper : " + ibatis.ToString("F3") + " / Direct ADO.NET: " + adonet.ToString("F3") + " Ratio: " + ((ibatis / adonet)).ToString("F3"));

            System.GC.Collect();
        }
开发者ID:hejiquan,项目名称:iBATIS_2010,代码行数:74,代码来源:PerformanceTest.cs

示例10: ProgressReporter

        /// <summary>
        ///
        /// </summary>
        /// <param name="totalWork">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <param name="title">
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="barLength">
        /// A <see cref="System.Int32"/>
        /// </param>
        public ProgressReporter(int totalWork, string title, int barLength)
        {
            plussesPrinted = 0;
            totalPlusses = barLength - title.Length;
            frequency = (double)totalWork / (double)totalPlusses;
            count = frequency;
            timer = new Timer ();
            timer.Start ();

            Console.Write ("  > " + title + ": [");
            left = Console.CursorLeft;
            right = left + totalPlusses - 1;
            Console.CursorLeft = right;
            Console.Write ("]");
            Console.CursorLeft = left;
        }
开发者ID:Kintaro,项目名称:Art,代码行数:28,代码来源:ProgressReporter.cs


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