• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Threading.Thread类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Play

 /// <summary>
 /// Plays the specified wav path.
 /// </summary>
 /// <param name="wavPath">The wav path.</param>
 public static void Play(string wavPath)
 {
     var thPlay = new System.Threading.Thread(THPlay);
     thPlay.IsBackground = true;
     threadWavPath = wavPath;
     thPlay.Start();
 }
开发者ID:alexisjojo,项目名称:ktibiax,代码行数:11,代码来源:Sound.cs


示例17: DriveDetector

 // Insert / remove threads must be executed on a different thread as they are called within WndProc().
 // System.Windows.Forms.Invoke also wont work as we are within WndProc at the time.
 // QueryRemove does not use the thread as it requires an immediate response for the application to allow removal, just
 // dont call any COM stuff when responding to a QueryRemove
 public DriveDetector( Control control )
 {
     mControl = control;
     mControlHandle = mControl.Handle;
     mEventHandlerThread = new System.Threading.Thread( new System.Threading.ThreadStart( OnEventHandlerThreadStart ) );
     mEventHandlerThread.Start();
 }
开发者ID:peteward44,项目名称:auto-usb-backup,代码行数:11,代码来源:DriveDetector.cs


示例18: Package

		public static IAsyncOperation Package (MonoMacProject project, ConfigurationSelector configSel,
			MonoMacPackagingSettings settings, FilePath target)
		{
			IProgressMonitor mon = IdeApp.Workbench.ProgressMonitors.GetOutputProgressMonitor (
				GettextCatalog.GetString ("Packaging Output"),
				MonoDevelop.Ide.Gui.Stock.RunProgramIcon, true, true);
			
			 var t = new System.Threading.Thread (() => {
				try {
					using (mon) {
						BuildPackage (mon, project, configSel, settings, target);
					}	
				} catch (Exception ex) {
					mon.ReportError ("Unhandled error in packaging", null);
					LoggingService.LogError ("Unhandled exception in packaging", ex);
				} finally {
					mon.Dispose ();
				}
			}) {
				IsBackground = true,
				Name = "Mac Packaging",
			};
			t.Start ();
			
			return mon.AsyncOperation;
		}
开发者ID:nieve,项目名称:monodevelop,代码行数:26,代码来源:MonoMacPackaging.cs


示例19: Begin

        private Socket SOCKET; //receive socket

        #endregion Fields

        #region Methods

        public void Begin()
        {
            connect:
            SOCKET = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            SOCKET.Connect(IPAddress.Parse("127.0.0.1"), 2404);
            Console.WriteLine("S104 establish a link successfully, try to receive...");

            RCV_THREAD = new System.Threading.Thread(BeginReceive);
            RCV_THREAD.Start(SOCKET);

            while (true)
            {
                System.Threading.Thread.Sleep(4000);
                this.Send_UFram(Uflag.testfr_active);
                if (RCVD_NUM >= 20000)
                {
                    SOCKET.Shutdown(SocketShutdown.Receive);
                    RCV_THREAD.Abort();
                    System.Threading.Thread.Sleep(4000);
                    SOCKET.Shutdown(SocketShutdown.Send);
                    SOCKET.Dispose();

                    RCVD_NUM = 0;
                    goto connect;
                }
                if (DateTime.Now - lastTime > new TimeSpan(0, 0, 4))
                {
                    this.Send_SFram(RCVD_NUM);
                    Console.WriteLine("overtime send S fram...");
                }
            }
        }
开发者ID:Wave-Maker,项目名称:S104,代码行数:38,代码来源:S104.cs


示例20: BUT_connect_Click

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

                t12 = new System.Threading.Thread(new System.Threading.ThreadStart(mainloop))
                {
                    IsBackground = true,
                    Name = "Nmea base Input"
                };
                t12.Start();

                BUT_connect.Text = Strings.Stop;
            }
        }
开发者ID:jackmaynard,项目名称:MissionPlanner,代码行数:35,代码来源:MovingBase.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Threading.Timer类代码示例发布时间:2022-05-24
下一篇:
C# Tasks.TaskCompletionSource类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap