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


C# Thread.Run方法代码示例

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


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

示例1: ThreadWaitTillAllCompleteTest

        public void ThreadWaitTillAllCompleteTest()
        {
            counter = 0;

            Thread[] threads = new Thread[10];
            for(int i = 0; i < threads.Length; i++) {
                threads[i] = new Thread(() => {
                    Thread.SleepInSeconds(Random.Uint.LessThan(10));
                    counter++;
                });
            }

            threads.Run();
            Assert.IsTrue(counter == 10);
        }
开发者ID:BobAlmighty,项目名称:HardlyBot,代码行数:15,代码来源:ThreadHelpersTests.cs

示例2: ThrottleIdTest

        public void ThrottleIdTest()
        {
            DateTime start = DateTime.Now;

            Thread[] threads = new Thread[10];
            for(int i = 0; i < 10; i++) {
                threads[i] = new Thread(() => {
                    throttleTest(counter++);
                });
            }

            threads.Run();

            TimeSpan span = DateTime.Now - start;
            Assert.IsTrue(span > new TimeSpan(0, 0, 9));
            Assert.IsTrue(span < new TimeSpan(0, 0, 90));
        }
开发者ID:BobAlmighty,项目名称:HardlyBot,代码行数:17,代码来源:ThrottleTests.cs

示例3: OnCreate

		protected override void OnCreate(Bundle bundle)
		{
			base.OnCreate(bundle);
			
			SetContentView(Resource.Layout.Main);

			var list = FindViewById<ListView>(Resource.Id.TestsList);
			var selectButton = FindViewById<Button>(Resource.Id.SelectAllButton);
			var deselectButton = FindViewById<Button>(Resource.Id.DeselectAllButton);
			var runTestsButton = FindViewById<Button>(Resource.Id.RunTests);

			var tests = GetAllTests();
			MarkAllAs(tests, true);

			list.Adapter = new TestListAdapter(this, tests);

			selectButton.Click += (sender, args) =>
			{
				MarkAllAs(tests, true);

				list.Adapter = new TestListAdapter(this, tests);
			};

			deselectButton.Click += (sender, args) =>
			{
				MarkAllAs(tests, false);

				list.Adapter = new TestListAdapter(this, tests);
			};

			runTestsButton.Click += (sender, args) =>
			{
				SetContentView(Resource.Layout.Testing);
				var selectedTests = tests.Where(item => item.Selected).ToList();
				var thread = new Thread(() => RunTests(selectedTests));
				thread.Run();
			};
		}
开发者ID:925coder,项目名称:ravendb,代码行数:38,代码来源:TestsActivity.cs

示例4: LogObserverThreadSafeTest

        public void LogObserverThreadSafeTest()
        {
            ConfirmNotListening();

            Log.RegisterListener(listenTest, Log.MessageType.ALL);

            int loopCount = 3;
            Thread[] threads = new Thread[5];
            string message = "123.";

            for(int i = 0; i < threads.Length; i++) {
                threads[i] = new Thread(() => {
                    int p = 0;
                    p++;

                    for(int j = 0; j < loopCount; j++) {
                        Log.info(message);
                    }
                });
            }

            threads.Run();
            string repeatedMessage = "";

            for(int i = 0; i < loopCount * threads.Length; i++) {
                repeatedMessage += message;
            }

            Assert.AreEqual(repeatedMessage, listenTestMessages);

            listenTestMessages = "";
             Log.DeregisterListener(listenTest);
            ConfirmNotListening();
        }
开发者ID:hardlydifficult,项目名称:HardlyBot,代码行数:34,代码来源:LogTests.cs


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