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


C# Threading.Thread类代码示例

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


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

示例1: reConnect

        public void reConnect()
        {
            clientSocket.Close();
            clientSocket = null;
            sendBuffer = new byte[1024];//Send buffer //c# automatic assigesd to 0     

            try
            {
                clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                System.Threading.Thread tt = new System.Threading.Thread(delegate()
                {
                    try
                    {
                        clientSocket.Connect(ip, port);
                    }
                    catch (Exception ee)
                    {
                        //MessageBox.Show(ee.Message + "\r\n From:" + this);
                    }
                });
                tt.Start();

            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message + "\r\n From:" + this);
            }
        }
开发者ID:Season02,项目名称:MK2.0,代码行数:29,代码来源:socket.cs

示例2: BUT_connect_Click

        private void BUT_connect_Click(object sender, EventArgs e)
        {
            if (comPort.IsOpen)
            {
                threadrun = false;
                comPort.Close();
                BUT_connect.Text = Strings.Connect;
            }
            else
            {
                try
                {
                    comPort.PortName = CMB_serialport.Text;
                }
                catch { CustomMessageBox.Show(Strings.InvalidPortName); return; }
                try {
                comPort.BaudRate = int.Parse(CMB_baudrate.Text);
                } catch {CustomMessageBox.Show(Strings.InvalidBaudRate); return;}
                try {
                comPort.Open();
                } catch {CustomMessageBox.Show("Error Connecting\nif using com0com please rename the ports to COM??"); return;}

                t12 = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop))
                {
                    IsBackground = true,
                    Name = "Nmea output"
                };
                t12.Start();
            }
        }
开发者ID:jackmaynard,项目名称:MissionPlanner,代码行数:30,代码来源:SerialOutputNMEA.cs

示例3: StartHostAndClient_SimpleSyncMethodSyncCallWithAsync_Success

        public async void StartHostAndClient_SimpleSyncMethodSyncCallWithAsync_Success()
        {
            bool @continue = false;
            var thread = new System.Threading.Thread(() =>
            {
                using (var host = new WcfExampleServiceHost("localhost:10000"))
                {
                    host.Start();
                    @continue = true;
                    while (@continue)
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                    host.Close();
                }
            });
            thread.Start();

            while ([email protected])
            {
                System.Threading.Thread.Sleep(10);
            }

            var client = new WcfExampleServiceAsyncClient("localhost:10000");
            SimpleSyncMethodResponseModel responseSimpleSyncMethod = client.SimpleSyncMethod(new SimpleSyncMethodRequestModel { Message = "Hello World" });
            Assert.IsNotNull(responseSimpleSyncMethod);
            Assert.AreEqual("SimpleSyncMethod: Hello World", responseSimpleSyncMethod.Message);

            @continue = false;

            thread.Join();
        }
开发者ID:CasperWollesen,项目名称:CW.Samples,代码行数:32,代码来源:WcfExampleServiceUnitTests.cs

示例4: Start

        public void Start(Action run)
        {
            Debug.Assert(!isRunning);

            thread = new System.Threading.Thread(new System.Threading.ThreadStart(run));
            thread.Start();
        }
开发者ID:hardlydifficult,项目名称:HardlyBot,代码行数:7,代码来源:Threadable.cs

示例5: DiscoverDynamicCategories

        public override int DiscoverDynamicCategories()
        {
            _thread = new System.Threading.Thread(new System.Threading.ThreadStart(ReadEPG));
            _thread.Start();
 
            Settings.Categories.Clear();
            RssLink cat = null;

            cat = new RssLink()
            {
                Name = "Channels",
                Other = "channels",
                Thumb = "http://arenavision.in/sites/default/files/FAVICON_AV2015.png",
                HasSubCategories = false
            };
            Settings.Categories.Add(cat);

            cat = new RssLink()
            {
                Name = "Agenda",
                Other = "agenda",
                Thumb = "http://arenavision.in/sites/default/files/FAVICON_AV2015.png",
                HasSubCategories = false
            };
            Settings.Categories.Add(cat);

            Settings.DynamicCategoriesDiscovered = true;
            return Settings.Categories.Count;
        }
开发者ID:offbyoneBB,项目名称:mp-onlinevideos2,代码行数:29,代码来源:ArenavisionUtil.cs

示例6: runUpload

 public static void runUpload( )
 {
     if (Properties.Settings.Default.firstrun)
         return;
     NameValueCollection postdata = new NameValueCollection();
     postdata.Add("u", Properties.Settings.Default.username);
     postdata.Add("p", Properties.Settings.Default.password);
     if (!Clipboard.ContainsImage() && !Clipboard.ContainsText()) {
         nscrot.balloonText("No image or URL in clipboard!", 2);
         return;
     }
     if (!Clipboard.ContainsText()) {
         Image scrt = Clipboard.GetImage();
         System.Threading.Thread upld = new System.Threading.Thread(( ) =>
         {
             nscrot.uploadScreenshot(postdata, scrt);
         });
         upld.SetApartmentState(System.Threading.ApartmentState.STA);
         upld.Start();
     } else {
         string lURL = Clipboard.GetText();
         System.Threading.Thread shrt = new System.Threading.Thread(( ) =>
         {
             nscrot.shorten(lURL);
         });
         shrt.SetApartmentState(System.Threading.ApartmentState.STA);
         shrt.Start();
     }
 }
开发者ID:Maffsie,项目名称:NetScrot,代码行数:29,代码来源:Program.cs

示例7: watch

 public watch()
 {
     t = new System.Threading.Thread(new System.Threading.ThreadStart(loop));
     s = new udpstate();
     s.e = new IPEndPoint(IPAddress.IPv6Any, 9887);
     s.u = new UdpClient(s.e);
 }
开发者ID:snoj,项目名称:IPv6-Forwarder-NAT,代码行数:7,代码来源:program.cs

示例8: webclient

 public webclient(Stream netstream, string path)
 {
     Path = path;
     clientStream = netstream;
     System.Threading.Thread mythread = new System.Threading.Thread(new System.Threading.ThreadStart(thetar));
     mythread.Start();
 }
开发者ID:BGCX262,项目名称:zuneusermarketplace-svn-to-git,代码行数:7,代码来源:appserver.cs

示例9: Ajouter_Click

 private void Ajouter_Click(object sender, EventArgs e)
 {
     System.Threading.Thread monthread = new System.Threading.Thread(new System.Threading.ThreadStart(Ajout));
     monthread.Start();
     this.Close();
     LoadPerso();
 }
开发者ID:Otomo07,项目名称:test,代码行数:7,代码来源:AdminSup.cs

示例10: Run

        public void Run()
        {
            if ((Site == null) || (Site.ID < 1))
            {
                return;
            }

            if ((MailTo == "") || (Subject == "") || (Body == ""))
            {
                new Log("System").Write("Send Email: MailTo, Subject or Body parameters error.");

                return;
            }

            EmailServer_From = Site.SiteOptions["Opt_EmailServer_From"].Value.ToString();
            EmailServer_EmailServer = Site.SiteOptions["Opt_EmailServer_EmailServer"].Value.ToString();
            EmailServer_User = Site.SiteOptions["Opt_EmailServer_UserName"].Value.ToString();
            EmailServer_Password = Site.SiteOptions["Opt_EmailServer_Password"].Value.ToString();

            if ((EmailServer_From == "") || (EmailServer_EmailServer == "") || (EmailServer_User == ""))
            {
                new Log("System").Write("Send Email: Read EmailServer configure fail.");

                return;
            }

            lock (this) // 确保临界区被一个 Thread 所占用
            {
                thread = new System.Threading.Thread(new System.Threading.ThreadStart(Do));
                thread.IsBackground = true;

                thread.Start();
            }
        }
开发者ID:ichari,项目名称:ichari,代码行数:34,代码来源:SendEmailTask.cs

示例11: Run

        public void Run()
        {
            //if ((ElectronTicket_HPCQ_Getway == "") || (ElectronTicket_HPCQ_UserName == "") || (ElectronTicket_HPCQ_UserPassword == ""))
            //{
            //    log.Write("ElectronTicket_XGCQ Task 参数配置不完整.");

            //    return;
            //}

            // 已经启动
            if (State == 1)
            {
                return;
            }

            lock (this) // 确保临界区被一个 Thread 所占用
            {
                State = 1;

                gCount1 = 0;

                thread = new System.Threading.Thread(new System.Threading.ThreadStart(Do));
                thread.IsBackground = true;

                thread.Start();

                log.Write("ElectronTicket_XGCQ Task Start.");
            }
        }
开发者ID:ichari,项目名称:ichari,代码行数:29,代码来源:XGCQ.cs

示例12: SendNonQuery

 protected void SendNonQuery(string stmt)
 {
     var pts = new System.Threading.ParameterizedThreadStart(_SendNonQuery);
     System.Threading.Thread t = new System.Threading.Thread(pts);
     t.Start(stmt);
     t.Join();
 }
开发者ID:MindFlavor,项目名称:BackupToUrlWithRotation,代码行数:7,代码来源:DBUtil.cs

示例13: ActionWindowLoaded

        private async void ActionWindowLoaded(object sender, RoutedEventArgs e)
        {
            if (count == 0)
            {
                id = Properties.Settings.Default.UserID;
                //ClientNameTextBox.Text = id;
                Active = true;
                Thread = new System.Threading.Thread(() =>
                {
                    Connection = new HubConnection(Host);
                    Proxy = Connection.CreateHubProxy("SignalRMainHub");

                    Proxy.On<string, string>("addmessage", (name, message) => OnSendData(DateTime.Now.ToShortTimeString()+"    ["+ name + "]\t " + message));
                    Proxy.On("heartbeat", () => OnSendData("Recieved heartbeat <3"));
                    Proxy.On<HelloModel>("sendHelloObject", hello => OnSendData("Recieved sendHelloObject " + hello.Molly + " " + hello.Age));

                    Connection.Start();

                    while (Active)
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                }) { IsBackground = true };
                
                Thread.Start();
                
                count++;
            }

        }
开发者ID:xomidar,项目名称:AcademyManagementSystem,代码行数:30,代码来源:ChatPage.xaml.cs

示例14: Start

        public void Start(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
        {
            if (!GetAvailablePorts().Contains(portName))
            {
                throw new Exception(string.Format("Unknown serial port: {0}", portName));
            }

            // Start the timer to empty the receive buffer (in case data smaller than MAX_RECEIVE_BUFFER is received)
            _bufferTimer = new Timer();
            _bufferTimer.Interval = BUFFER_TIMER_INTERVAL;
            _bufferTimer.Elapsed += _bufferTimer_Elapsed;
            _bufferTimer.Start();

            // Instantiate new serial port communication
            _serialPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits);

            // Open serial port communication
            _serialPort.Open();

            // Check that it is actually open
            if (!_serialPort.IsOpen)
            {
                throw new Exception(string.Format("Could not open serial port: {0}", portName));
            }

            _serialPort.ReadTimeout = 100; // Milliseconds

            _readThread = new System.Threading.Thread(ReadThread);
            _readThreadRunning = true;
            _readThread.Start();
        }
开发者ID:whitestone-no,项目名称:open-serial-port-monitor,代码行数:31,代码来源:SerialReader.cs

示例15: startPreview

        private void startPreview()
        {
            #region Create capture object if it is not already created

            if (_capture == null)
            {
                try
                {
                    _capture = new Capture();
                }
                catch (NullReferenceException excpt)
                {
                    MessageBox.Show(excpt.Message);
                }
            }

            #endregion

            #region Start the capture process and display in the preview window

            if (_capture != null)
            {
                //start the capture
                
                //Application.Idle += ProcessFrame;
                captureEnabled = true;
                System.Threading.Thread capThread = new System.Threading.Thread(new System.Threading.ThreadStart(captureThread));
                capThread.Start();

            }

            #endregion
        }
开发者ID:thaisdannyrocha,项目名称:monobooth,代码行数:33,代码来源:frmMain.cs


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