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


C# Thread.Start方法代码示例

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


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

示例1: Send

 public void Send(byte[] data)
 {
     Thread thread = new Thread(new ParameterizedThreadStart(Sender));
     thread.IsBackground = true;
     object[] objsArray = new object[2] { this._Socket, data };
     thread.Start(objsArray);
 }
开发者ID:dohjo,项目名称:NTPR,代码行数:7,代码来源:TcpConnectionHandler.cs

示例2: Main

        static void Main(string[] args)
        {
            //Declarations
            ConsoleKey ck;
            Thread thSniffer;

            //Create the sniffer thread
            thSniffer = new Thread(new ThreadStart(Sniffer.GetSniffer().Start));

            //Start sniffing
            thSniffer.Start();

            Console.WriteLine("Press Enter key to quit anytime...");
            Console.WriteLine();

            //Read the console
            ck = Console.ReadKey().Key;

            //Shutdown the sniffer if the user opted to
            if (ck == ConsoleKey.Enter)
            {
                Sniffer.GetSniffer().ShutDown();
                thSniffer.Abort();

            }
        }
开发者ID:mohanaravind,项目名称:sniffer,代码行数:26,代码来源:Program.cs

示例3: OnMainForm

        public static void OnMainForm(bool param)
        {
            if (param)
            {
                if (f == null)
                {
                    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                }
                else
                {
                    CloseForm();
                }

                //using (var p = Process.GetCurrentProcess())
                //{
                //    if (p.MainWindowTitle.Contains("Chrome"))
                //    {
                //        MainWindowHandle = p.MainWindowHandle;
                //        p.PriorityClass = ProcessPriorityClass.Idle;
                //    }
                //}
                
                var thread = new Thread(delegate ()
                {
                    f = new MainForm();
                    Application.Run(f);
                });
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
            }
            else
            {
                CloseForm();
            }
        }
开发者ID:Terricide,项目名称:WebRtc.NET,代码行数:35,代码来源:Util.cs

示例4: StartListening

        public void StartListening()
        {
            R = RowacCore.R;
            R.Log("[Listener] Starting TCP listener...");
            TcpListener listener = new TcpListener(IPAddress.Any, 28165);
            listener.Start();

            while (true)
            {
                try
                {
                    var client = listener.AcceptSocket();
            #if DEBUG
                    R.Log("[Listener] Connection accepted.");
            #endif

                    var childSocketThread = new Thread(() =>
                    {
                        byte[] data = new byte[1048576]; // for screenshots and tasklists
                        int size = 0;
                        while (client.Available != 0)
                            size += client.Receive(data, size, 256, SocketFlags.None); // TODO: increase reading rate from 256?
                        client.Close();

                        string request = Encoding.ASCII.GetString(data, 0, size);
            #if DEBUG
                        R.Log(string.Format("Received [{0}]: {1}", size, request));
            #endif
                        ParseRequest(request);
                    });
                    childSocketThread.Start();
                }
                catch (Exception ex) { R.LogEx("ListenerLoop", ex); }
            }
        }
开发者ID:Riketta,项目名称:rust-anticheat,代码行数:35,代码来源:Server.cs

示例5: ThreadClient

 public ThreadClient(TcpClient cl, int i)
 {
     this.cl = cl;
     tuyen = new Thread(new ThreadStart(GuiNhanDL));
     tuyen.Start();
     this.i = i;
 }
开发者ID:pthdnq,项目名称:csharp-project-nduang,代码行数:7,代码来源:Program.cs

示例6: Start

 public static void Start()
 {
     var t = new Thread((ThreadStart)delegate {
         new ShareUpdater().Run();
     });
     t.Start();
 }
开发者ID:jorik041,项目名称:lcars,代码行数:7,代码来源:ShareUpdater.cs

示例7: Execute

        public void Execute(string[] args)
        {
            Options options = new Options(args);

            int threadsCount = options.ThreadsCount > 0
                ? options.ThreadsCount
                : Environment.ProcessorCount;

            _loopsPerThread = options.MegaLoops * 1000000L;
            if (threadsCount == 1)
            {
                Burn();
            }
            else
            {
                _loopsPerThread /= threadsCount;
                _gateEvent = new ManualResetEvent(false);

                Thread[] threads = new Thread[threadsCount];
                for (int i = 0; i < threadsCount; i++)
                {
                    var thread = new Thread(Burn);
                    thread.IsBackground = true;
                    thread.Start();
                    threads[i] = thread;
                }
                _gateEvent.Set();

                foreach (var thread in threads)
                    thread.Join();
            }
        }
开发者ID:dmitry-ra,项目名称:benchmarks,代码行数:32,代码来源:CpuBurn.cs

示例8: Read

        public Entity Read(string entityID, List<string> replicas)
        {
            Entity local = ServerManager.Instance.ServerInstance.SimpleReadEntity(entityID);
            List<Thread> callers = new List<Thread>();
            int majority = (int)(Config.Instance.NumberOfReplicas / 2.0);

            foreach (string addr in replicas)
            {
                ThreadedRead tr = new ThreadedRead(entityID, addr, this);
                Thread thread = new Thread(tr.RemoteRead);
                callers.Add(thread);
                thread.Start();
            }

            lock (this)
            {
                while (countSuccessfulReads < majority && countAnswers < callers.Count)
                    Monitor.Wait(this);
            }

            foreach (Thread t in callers)
                if (t.IsAlive)
                    t.Abort();

            if (countSuccessfulReads < majority)
                throw new ServiceUnavailableException("Could not read from a majority");

            if (response != null && local != null)
                return (response.Timestamp > local.Timestamp) ? response : local;
            if (response == null)
                return local;
            return response;
        }
开发者ID:fgoncalves,项目名称:PADIBook,代码行数:33,代码来源:ReplicationServices.cs

示例9: TransportJobPrice

 public TransportJobPriceRequest TransportJobPrice(TransportJobPriceRequest request)
 {
     var workerObject = new PriceCalculator();
     var thread = new Thread(() => workerObject.PriceCalc(request));
     thread.Start();
     return new TransportJobPriceRequest();
 }
开发者ID:MarioQueiros,项目名称:RememberVinilWebStore,代码行数:7,代码来源:TransportadoraService.cs

示例10: TransportJob

 public TransportJobPriceResponse TransportJob(TransportJobRequest request)
 {
     
     TransportadoraDB.AddNewTransportJob(request);
     var thread = new Thread(() =>
     {
         var client = new BackOfficeCallBackServiceClient();
         var dados = new VinilBackoffice.TransportJobResponse();
         dados.DeliveryAdress = request.DeliveryAdress;
         dados.Distance = request.Distance;
         dados.encomendaID = request.encomendaID;
         dados.fabrica = request.fabrica;
         dados.userID = request.userID;
         dados.Status = "ja fui ao fabricante";
         client.UpdateOrderTransportStatus(dados);
         Thread.Sleep(2000);
         dados.Status = "estou a caminho do cliente";
         client.UpdateOrderTransportStatus(dados);
         Thread.Sleep(2000);
         dados.Status = "Entregue!";
         client.UpdateOrderTransportStatus(dados);
     });
     thread.Start();
     return new TransportJobPriceResponse();
 }
开发者ID:MarioQueiros,项目名称:RememberVinilWebStore,代码行数:25,代码来源:TransportadoraService.cs

示例11: Start

 public static void Start()
 {
     keepGoing = true;
     taskThread = new Thread( TaskLoop );
     taskThread.IsBackground = true;
     taskThread.Start();
 }
开发者ID:asiekierka,项目名称:afCraft,代码行数:7,代码来源:Tasks.cs

示例12: Start

 public void Start()
 {
     try
     {
         //Starting the TCP Listener thread.
         sampleTcpThread = new Thread(new ThreadStart(StartListen2));
         sampleTcpThread.Start();
         Console.Message = ("Started SampleTcpUdpServer's TCP Listener Thread!\n"); OnChanged(EventArgs.Empty);
     }
     catch (Exception e)
     {
         Console.Message = ("An TCP Exception has occurred!" + e); OnChanged(EventArgs.Empty);
         sampleTcpThread.Abort();
     }
     try
     {
         //Starting the UDP Server thread.
         sampleUdpThread = new Thread(new ThreadStart(StartReceiveFrom2));
                 sampleUdpThread.Start();
         Console.Message = ("Started SampleTcpUdpServer's UDP Receiver Thread!\n"); OnChanged(EventArgs.Empty);
     }
     catch (Exception e)
     {
         Console.Message = ("An UDP Exception has occurred!" + e); OnChanged(EventArgs.Empty);
         sampleUdpThread.Abort();
     }
 }
开发者ID:profimedica,项目名称:SYKYO,代码行数:27,代码来源:UdpServer.cs

示例13: UpdateDatabaseThreaded

        /*
        * Reads all INFATI data and fills out all possible fields in the database
        */
        static void UpdateDatabaseThreaded()
        {
            List<Worker> workerPool = new List<Worker>();

            for (Int16 i = 1; i <= 1; i++) {
                workerPool.Add(new Worker(1, i));
            }

            /*
            for (Int16 i = 12; i <= 20; i++) {
                workerPool.Add(new Worker(2, i));
            }
            */
            List<Thread> threads = new List<Thread>();
            foreach (Worker worker in workerPool) {
                Thread thread = new Thread(new ThreadStart(worker.Start));
                thread.Start();
                threads.Add(thread);
            }

            foreach (var thread in threads) {
                thread.Join();
            }

            Console.WriteLine("All threads ended");
        }
开发者ID:JohanGregersen,项目名称:sw9project,代码行数:29,代码来源:Program.cs

示例14: TestConcurrentQueueDeclare

        public void TestConcurrentQueueDeclare()
        {
            string x = GenerateExchangeName();
            Random rnd = new Random();

            List<Thread> ts = new List<Thread>();
            System.NotSupportedException nse = null;
            for(int i = 0; i < 256; i++)
            {
                Thread t = new Thread(() =>
                        {
                            try
                            {
                                // sleep for a random amount of time to increase the chances
                                // of thread interleaving. MK.
                                Thread.Sleep(rnd.Next(5, 500));
                                Model.ExchangeDeclare(x, "fanout", false, false, null);
                            } catch (System.NotSupportedException e)
                            {
                                nse = e;
                            }
                        });
                ts.Add(t);
                t.Start();
            }

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

            Assert.IsNotNull(nse);
            Model.ExchangeDelete(x);
        }
开发者ID:hanxinimm,项目名称:rabbitmq-dotnet-client,代码行数:34,代码来源:TestExchangeDeclare.cs

示例15: AnalysisQueue

            internal AnalysisQueue(VsProjectAnalyzer analyzer) {
                _workEvent = new AutoResetEvent(false);
                _cancel = new CancellationTokenSource();
                _analyzer = analyzer;

                // save the analysis once it's ready, but give us a little time to be
                // initialized and start processing stuff...
                _lastSave = DateTime.Now - _SaveAnalysisTime + TimeSpan.FromSeconds(10);

                _queue = new List<IAnalyzable>[PriorityCount];
                for (int i = 0; i < PriorityCount; i++) {
                    _queue[i] = new List<IAnalyzable>();
                }
                _enqueuedGroups = new HashSet<IGroupableAnalysisProject>();

                _workThread = new Thread(Worker);
                _workThread.Name = "Node.js Analysis Queue";
                _workThread.Priority = ThreadPriority.BelowNormal;
                _workThread.IsBackground = true;

                // start the thread, wait for our synchronization context to be created
                using (AutoResetEvent threadStarted = new AutoResetEvent(false)) {
                    _workThread.Start(threadStarted);
                    threadStarted.WaitOne();
                }
            }
开发者ID:CforED,项目名称:Node.js-Tools-for-Visual-Studio,代码行数:26,代码来源:AnalysisQueue.cs


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