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


C# Thread.Start方法代码示例

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


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

示例1: Run

        public void Run(System.Windows.Forms.IWin32Window wnd)
        {
            Thread thread = new Thread(DoWork);
            thread.Start();

            ShowDialog(wnd);
        }
开发者ID:otaviog,项目名称:Fruki,代码行数:7,代码来源:WorkProgressDialog.Designer.cs

示例2: Main

        private static void Main(string[] args)
        {
            var n = 10;

            var chickenFarm = new ChickenFarm();
            var token = chickenFarm.GetToken();
            var chickenFarmer = new Thread(chickenFarm.FarmSomeChickens) {Name = "TheChickenFarmer"};
            var chickenStore = new Retailer(token);
            chickenFarm.PriceCut += chickenStore.OnPriceCut;
            var retailerThreads = new Thread[n];
            for (var index = 0; index < retailerThreads.Length; index++)
            {
                retailerThreads[index] = new Thread(chickenStore.RunStore) {Name = "Retailer" + (index + 1)};
                retailerThreads[index].Start();
                while (!retailerThreads[index].IsAlive)
                {
                    ;
                }
            }
            chickenFarmer.Start();
            chickenFarmer.Join();
            foreach (var retailerThread in retailerThreads)
            {
                retailerThread.Join();
            }
        }
开发者ID:asu-cse445-cornholios,项目名称:Project2,代码行数:26,代码来源:Program.cs

示例3: MultiThread

        public void MultiThread()
        {
            int threadCount = 5;
             _threadedMessageCount = 100;
             int totalMessageCount = threadCount * _threadedMessageCount;

             List<Thread> threads = new List<Thread>();
             for (int thread = 0; thread < threadCount; thread++)
             {
            Thread t = new Thread(new ThreadStart(SendMessageThread));

            threads.Add(t);

            t.Start();
             }

             foreach (Thread t in threads)
             {
            t.Join();
             }

             POP3ClientSimulator.AssertMessageCount(_account.Address, "test", totalMessageCount);

             for (int i = 0; i < totalMessageCount; i++)
             {
            string content = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test");

            Assert.IsTrue(content.Contains("X-Spam-Status"), content);
             }
        }
开发者ID:digitalsoft,项目名称:hmailserver,代码行数:30,代码来源:SpamAssassin.cs

示例4: CheckForLoops

 private static void CheckForLoops(IEnumerable<Activity> activities)
 {
     var isCaughtProperly = false;
     var thread = new System.Threading.Thread(
         () =>
             {
                 try {
                     activities.CriticalPath(p => p.Predecessors, l => (long)l.Duration);
                 }
                 catch (System.InvalidOperationException ex) {
                     System.Console.WriteLine("Found problem: " + ex.Message);
                     isCaughtProperly = true;
                 }
             }
         );
     thread.Start();
     for (var i = 0; i < 100; i++) {
         Thread.Sleep(100); // Wait for 10 seconds - our thread should finish by then
         if (thread.ThreadState != ThreadState.Running)
             break;
     }
     if(thread.ThreadState ==ThreadState.Running)
         thread.Abort();
     System.Console.WriteLine(isCaughtProperly
                                  ? "Critical path caught the loop"
                                  : "Critical path did not find the loop properly");
 }
开发者ID:pourmand,项目名称:amaal,代码行数:27,代码来源:CriticalPathMethod.cs

示例5: SetUp

        public void SetUp()
        {
            runner = new TestRunner(x => x.AddFixture<SlowFixture>());
            test = new Test("slow test").With(Section.For<SlowFixture>().WithStep("GoSlow"));

            var reset = new ManualResetEvent(false);
            var running = new ManualResetEvent(false);

            var thread = new Thread(() =>
            {
                running.Set();
                Debug.WriteLine("Starting to run");
                test.LastResult = runner.RunTest(new TestExecutionRequest()
                {
                    Test = test,
                    TimeoutInSeconds = 60
                });

                test.LastResult.ShouldNotBeNull();
                Debug.WriteLine("finished running");
                reset.Set();
            });

            thread.Start();
            running.WaitOne();
            Thread.Sleep(1000);

            Debug.WriteLine("Aborting now!");
            runner.Abort();
            Debug.WriteLine("Done aborting");

            reset.WaitOne(5000);
            test.LastResult.ShouldNotBeNull();
            Debug.WriteLine("completely done");
        }
开发者ID:wbinford,项目名称:storyteller,代码行数:35,代码来源:AbortTestSmokeTester.cs

示例6: Get

        // GET api/values?q=Microsoft.ApplicationInsights
        public string Get([FromUri]string q)
        {
            Thread t = new Thread(new ThreadStart(
                () =>
                {
                    IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");
                    List<IPackage> packages = repo.Search(q, true).ToList();

                    foreach (var p in packages)
                    {
                        lock (packagesListLock)
                        {
                            if (!this.packagesList.Contains(p.Id))
                            {
                                this.packagesList.Add("Search '" + q + "'", p);
                            }
                        }
                        Thread.Sleep(10);
                    }
                }));

            t.Start();

            return Process.GetCurrentProcess().Id.ToString();
        }
开发者ID:SergeyKanzhelev,项目名称:ILL,代码行数:26,代码来源:PackagesController.cs

示例7: RelayPort

 public RelayPort(Cpu.Pin pin, bool initialState, int timeout)
     : base(pin, initialState)
 {
     currentstate = initialState;
     relayThread = new Thread(new ThreadStart(RelayLoop));
     relayThread.Start();
 }
开发者ID:mbaldini,项目名称:NovaOS,代码行数:7,代码来源:RelayPort.cs

示例8: TcpServer

 public TcpServer(int port)
 {
     listener = new TcpListener(port);
     listenThread = new Thread(ListenThreadFun);
     listenThread.Start();
     encoder = new ASCIIEncoding();
 }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:7,代码来源:TcpServer.cs

示例9: InterfaceReRegisteredFromClassToInstance_Success

        public void InterfaceReRegisteredFromClassToInstance_Success()
        {
            var c = new Container();
            IEmptyClass emptyClass = new EmptyClass();
            c.RegisterType<IEmptyClass, EmptyClass>().AsPerThread();
            IEmptyClass emptyClass1 = null;
            IEmptyClass emptyClass2 = null;
            IEmptyClass emptyClass3 = null;
            IEmptyClass emptyClass4 = null;

            var thread = new Thread(() =>
            {
                emptyClass1 = c.Resolve<IEmptyClass>(ResolveKind.FullEmitFunction);
                emptyClass2 = c.Resolve<IEmptyClass>(ResolveKind.FullEmitFunction);

                c.RegisterInstance(emptyClass).AsPerThread();
                emptyClass3 = c.Resolve<IEmptyClass>(ResolveKind.FullEmitFunction);
                emptyClass4 = c.Resolve<IEmptyClass>(ResolveKind.FullEmitFunction);
            });
            thread.Start();
            thread.Join();

            Assert.AreEqual(emptyClass1, emptyClass2);
            Assert.AreEqual(emptyClass, emptyClass3);
            Assert.AreEqual(emptyClass3, emptyClass4);
            Assert.AreNotEqual(emptyClass1, emptyClass3);
        }
开发者ID:amularczyk,项目名称:NiquIoC,代码行数:27,代码来源:ReRegistereInterfaceTests.cs

示例10: ResizingThreadTableWorks

 public void ResizingThreadTableWorks()
 {
     var defaultThreadTableSize = Environment.ProcessorCount;
     var threads = new List<WaitHandle>();
     var counter = new ReferenceCounter();
     var obj = new object();
     for (int threadNumber = 0; threadNumber < defaultThreadTableSize * 2; threadNumber++)
     {
         var thread = new Thread(new ThreadStart(() =>
         {
             var handle = new AutoResetEvent(false);
             threads.Add(handle);
             for (int itteration = 0; itteration < 100; itteration++)
             {
                 counter.AddReference(obj);
                 Thread.Sleep(10);
                 counter.Release(obj);
             }
             handle.Set();
         }));
         thread.Start();
     }
     WaitHandle.WaitAll(threads.ToArray());
     Assert.Equal(0, (int)counter.GetGlobalCount(0));
 }
开发者ID:ahsonkhan,项目名称:corefxlab,代码行数:25,代码来源:ReferenceCounterTests.cs

示例11: CanEnumerateSafely

 public void CanEnumerateSafely()
 {
     var strings = LangTestHelpers.RandomStrings(1000, 50);
     var results = new ConcurrentQueue<string>();
     using (var stringsEnumerator = strings.GetEnumerator())
     {
         var tse = new ThreadSafeEnumerator<string>(stringsEnumerator);
         var threads = new List<Thread>();
         for (var i = 0; i < 10; i++)
         {
             var thread = new Thread(() =>
             {
                 string it = null;
                 while (tse.TryGetNext(ref it))
                 {
                     results.Enqueue(it);
                 }
             });
             thread.Start();
             threads.Add(thread);
         }
         foreach (var thread in threads)
         {
             thread.Join();
         }
     }
     CollectionAssert.AreEquivalent(strings, results);
 }
开发者ID:shabtaisharon,项目名称:ds3_net_sdk,代码行数:28,代码来源:TestThreadSafeEnumerator.cs

示例12: SetUp

        public void SetUp()
        {
            var settings = new Settings();
            if (!CEF.Initialize(settings))
            {
                Assert.Fail();
            }

            var thread = new Thread(() =>
            {
                var form = new Form();
                form.Shown += (sender, e) =>
                {
                    Browser = new WebBrowser()
                    {
                        Parent = form,
                        Dock = DockStyle.Fill,
                    };

                    createdEvent.Set();
                };

                Application.Run(form);
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            createdEvent.WaitOne();
        }
开发者ID:boydlee,项目名称:CefSharp,代码行数:29,代码来源:Fixture.cs

示例13: StartBiddingIn

 public void StartBiddingIn(FakeAuctionServer auction)
 {
     var thread = new Thread(StartApplication);
     thread.Start();
     driver = new AuctionSniperDriver(1000, ApplicationName);
     driver.ShowsSniperStatus(StatusJoining);
 }
开发者ID:cerishaw,项目名称:GoosWalkthrough,代码行数:7,代码来源:ApplicationRunner.cs

示例14: ClassReRegisteredFromClassToObjectFactory_Success

        public void ClassReRegisteredFromClassToObjectFactory_Success()
        {
            var c = new Container();
            c.RegisterType<EmptyClass>().AsPerThread();
            EmptyClass emptyClass1 = null;
            EmptyClass emptyClass2 = null;
            EmptyClass emptyClass3 = null;
            EmptyClass emptyClass4 = null;

            var thread = new Thread(() =>
            {
                emptyClass1 = c.Resolve<EmptyClass>(ResolveKind.PartialEmitFunction);
                emptyClass2 = c.Resolve<EmptyClass>(ResolveKind.PartialEmitFunction);

                c.RegisterType<EmptyClass>(() => new EmptyClass()).AsPerThread();
                emptyClass3 = c.Resolve<EmptyClass>(ResolveKind.PartialEmitFunction);
                emptyClass4 = c.Resolve<EmptyClass>(ResolveKind.PartialEmitFunction);
            });
            thread.Start();
            thread.Join();

            Assert.AreEqual(emptyClass1, emptyClass2);
            Assert.AreEqual(emptyClass3, emptyClass4);
            Assert.AreNotEqual(emptyClass1, emptyClass3);
        }
开发者ID:amularczyk,项目名称:NiquIoC,代码行数:25,代码来源:ReRegistereClassTests.cs

示例15: Main

        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("'extractor.exe output_folder input.xef' to extract a .xef file.");
                return;
            }

            string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            string subFolderPath = System.IO.Path.Combine(myPhotos, args[0]);
            Directory.CreateDirectory(subFolderPath);

            using (Extractor extractor = new Extractor(subFolderPath))
            {
                extractor.ListenForFrames();

                string xefFileName = args[1];
                Console.WriteLine("Extracting frames from .xef file: {0}", xefFileName);

                Player player = new Player(xefFileName);
                Thread playerThread;
                playerThread = new System.Threading.Thread(new ThreadStart(player.PlayXef));
                playerThread.Start();
                playerThread.Join();

                extractor.Stop();
            }
        }
开发者ID:isalento,项目名称:XefFrameExtractor,代码行数:29,代码来源:Program.cs


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