當前位置: 首頁>>代碼示例>>C#>>正文


C# Thread.Start方法代碼示例

本文整理匯總了C#中System.Thread.Start方法的典型用法代碼示例。如果您正苦於以下問題:C# Thread.Start方法的具體用法?C# Thread.Start怎麽用?C# Thread.Start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Thread的用法示例。


在下文中一共展示了Thread.Start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: StartNewThread

        public static Thread StartNewThread(Action run)
        {
            Thread t = new Thread(run);
            t.Start();

            return t;
        }
開發者ID:hardlydifficult,項目名稱:HardlyBot,代碼行數:7,代碼來源:Thread.cs

示例2: Main

        static void Main(string[] args)
        {
            Random RandomNumber = new Random();

            Thread thread1 = new Thread(new ThreadClass("ONE", RandomNumber).PrintInfo);

            Thread thread2 = new Thread(new ThreadClass("TWO", RandomNumber).PrintInfo);

            Thread thread3 = new Thread(new ThreadClass("THREE", RandomNumber).PrintInfo);

            Thread thread4 = new Thread(new ThreadClass("FOUR", RandomNumber).PrintInfo);

            Thread thread5 = new Thread(new ThreadClass("FIVE", RandomNumber).PrintInfo);

            Thread thread6 = new Thread(new ThreadClass("SIX", RandomNumber).PrintInfo);

            Thread thread7 = new Thread(new ThreadClass("SEVEN", RandomNumber).PrintInfo);

            thread1.Start();
            thread2.Start();
            thread3.Start();
            thread4.Start();
            thread5.Start();
            thread6.Start();
            thread7.Start();
        }
開發者ID:giorgosrevis,項目名稱:C-Homeworks,代碼行數:26,代碼來源:Program.cs

示例3: QueueTask

        protected internal override void QueueTask(Task task)
        {
#if !FEATURE_PAL    // PAL doesn't support  eventing
            if (TplEtwProvider.Log.IsEnabled(EventLevel.Verbose, ((EventKeywords)(-1))))
            {
                Task currentTask = Task.InternalCurrent;
                Task creatingTask = task.m_parent;

                TplEtwProvider.Log.TaskScheduled(this.Id, currentTask == null ? 0 : currentTask.Id, 
                                                 task.Id, creatingTask == null? 0 : creatingTask.Id, 
                                                 (int) task.Options);
            }
#endif

            if ((task.Options & TaskCreationOptions.LongRunning) != 0)
            {
                // Run LongRunning tasks on their own dedicated thread.
                Thread thread = new Thread(s_longRunningThreadWork);
                thread.IsBackground = true; // Keep this thread from blocking process shutdown
                thread.Start(task);
            }
            else
            {
#if PFX_LEGACY_3_5
                ThreadPool.QueueUserWorkItem(s_taskExecuteWaitCallback, (object) task);
#else
                // Normal handling for non-LongRunning tasks.
                bool forceToGlobalQueue = ((task.Options & TaskCreationOptions.PreferFairness) != 0);
                ThreadPool.UnsafeQueueCustomWorkItem(task, forceToGlobalQueue);
#endif
            }
        }
開發者ID:modulexcite,項目名稱:IL2JS,代碼行數:32,代碼來源:ThreadPoolTaskScheduler.cs

示例4: CodeScanner

		public CodeScanner(Action beep, int scanTimeout, int upcLotTimeout)
		{
			this.beep = beep;
			this.ScanTimeout = scanTimeout;
			this.UPCLotTimeout = upcLotTimeout;

			thread = new Thread(ReadScanner);
			thread.Start();
		}
開發者ID:xyandro,項目名稱:NeoEdit,代碼行數:9,代碼來源:b.cs

示例5: FinishedLaunching

		// This method is invoked when the application has loaded its UI and its ready to run
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			window.AddSubview (navigation.View);
			
			// this method initializes the main menu Dialog
			var startupThread = new Thread (Startup as ThreadStart);
			startupThread.Start ();
			
			window.MakeKeyAndVisible ();
			return true;
		}
開發者ID:briandonahue,項目名稱:MonoTouch.MVVM,代碼行數:12,代碼來源:AppDelegateIPad.cs

示例6: btnServidor_Click

 private void btnServidor_Click(object sender, EventArgs e)
 {
     TcpListener newSock = new TcpListener(IPAddress.Any, 2000);
     newSock.Start();
     Console.WriteLine("Esperando por cliente");
     while (true)
     {
         TcpClient cliente = newSock.AcceptTcpClient();
         Thread t = new Thread(() => this.handleClient(cliente));
         t.IsBackground = true;
         t.Start();
     }
 }
開發者ID:Maldercito,項目名稱:psp,代碼行數:13,代碼來源:1449733259$Form1.cs

示例7: QueueTask

 /// <summary>
 /// Schedules a task to the ThreadPool.
 /// </summary>
 /// <param name="task">The task to schedule.</param>
 protected internal override void QueueTask(Task task)
 {
     if ((task.Options & TaskCreationOptions.LongRunning) != 0)
     {
         // Run LongRunning tasks on their own dedicated thread.
         Thread thread = new Thread(s_longRunningThreadWork);
         thread.IsBackground = true; // Keep this thread from blocking process shutdown
         thread.Start(task);
     }
     else
     {
         // Normal handling for non-LongRunning tasks.
         bool forceToGlobalQueue = ((task.Options & TaskCreationOptions.PreferFairness) != 0);
         ThreadPool.UnsafeQueueCustomWorkItem(task, forceToGlobalQueue);
     }
 }
開發者ID:kouvel,項目名稱:coreclr,代碼行數:20,代碼來源:ThreadPoolTaskScheduler.cs

示例8: Execute

        public void Execute()
        {
            var checkRunnable = new Runnable(() =>
            {

                const string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
                string entity = GenProductArgs();
                var buf = Util.httpPost(url, entity);

                string content = Encoding.Default.GetString(buf);
                _resultunifiedorder = DecodeXml(content);
                VoidPayWindow(content);
            });

            var checkThread = new Thread(checkRunnable);
            checkThread.Start();
        }
開發者ID:MicahelWang,項目名稱:MvvmHubs1,代碼行數:17,代碼來源:WeixinpayHelper.cs

示例9: Main

        static void Main()
        {
            string str = string.Empty;
            EventTimer myTimer = new EventTimer(1, DoAction);

            Thread timerThread = new Thread(myTimer.RunTimer);

            timerThread.Start();

            for (int i = 0; i < 100000; i++)
            {
                str += string.Format("{0}Test \r\n", action);
            }

            myTimer.StopTimer();
            Console.WriteLine(str);
        }
開發者ID:NikolayKostadinov,項目名稱:Homeworks,代碼行數:17,代碼來源:Program.cs

示例10: Main

        public static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Thread.CurrentThread.CurrentCulture.ClearCachedData();
            var thread = new Thread(
                s => ((CultureState)s).Result = Thread.CurrentThread.CurrentCulture);
            var state = new CultureState();
            thread.Start(state);
            thread.Join();
            CultureInfo culture = state.Result;

            Localizer.SetCulture(culture);
            Localizer.Initialize();

            Application.Run(new Shell());
        }
開發者ID:ericjohnolson,項目名稱:NadaNtd,代碼行數:18,代碼來源:Program.cs

示例11: Main

        static void Main(string[] args)
        {
            Debug.WriteLine("inSSIDer 2 version " + Application.ProductVersion + " Starting");
            //TODO: Make conmmand line option to enable logging on debug builds. Like /log
            #if DEBUG && LOG
            Log.Start();
            #endif
            Debug.WriteLine("Hook exception handlers");
            // Create new instance of UnhandledExceptionDlg:
            // NOTE: this hooks up the exception handler functions
            UnhandledExceptionDlg exDlg = new UnhandledExceptionDlg();
            InitializeExceptionHandler(exDlg);

            Debug.WriteLine("Check .NET configuration system");
            //Check for config system condition here
            if(!Settings.Default.CheckSettingsSystem())
            {
                //The settings system is broken, notify and exit
                MessageBox.Show(
                    Localizer.GetString("ConfigSystemError"),
                    "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            #if DEBUG && LOG
            frmTest ft = new frmTest();
            Thread debugThread = new Thread(() => Application.Run(ft));
            debugThread.Start();
            #endif

            //Initialize the scanner object before passing it to any interface
            ScanController scanner = new ScanController();
            Exception error;

            Debug.WriteLine("Initialize ScanController");
            scanner.Initialize(out error);
            if (error != null)
            {
                //An error!
                scanner.Dispose();
                scanner = null;
                //So the error handler will catch it
                //throw ex;

                //Log it
                Log.WriteLine(string.Format("Exception message:\r\n\r\n{0}\r\n\r\nStack trace:\r\n{1}", error.Message, error.StackTrace));

                if (error is System.ComponentModel.Win32Exception)
                {
                    //The wireless system failed
                    if (Utilities.IsXp())
                    {
                        MessageBox.Show(Localizer.GetString("WlanServiceNotFoundXP"), "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                    }
                    else
                    {
                        MessageBox.Show(Localizer.GetString("WlanServiceNotFound7"), "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                    }
                }
                else
                {
                    //Any other exceptions
                    MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Hand);
                }
            }

            if (scanner == null) return;

            //Start the scanning if it was last time and we have the last interface
            //Otherwise, if we only have the interface, but not scanning, just set the interface selector to the last interface.
            //TODO: Actually have the auto-start as an option. :)

            NetworkInterface netInterface = InterfaceManager.Instance.LastInterface;
            if (netInterface != null)
            {
                Debug.WriteLine("We have a last interface, start scanning with it.");
                //Set the interface
                scanner.Interface = netInterface;
                if (Settings.Default.scanLastEnabled)
                    scanner.StartScanning();
            }

            //The main form will run unless mini is specified
            IScannerUi form = null;

            Switching = Settings.Default.lastMini ? Utilities.SwitchMode.ToMini : Utilities.SwitchMode.ToMain;

            //if(Settings.Default.lastMini)
            //{
            //    Switching = Utilities.SwitchMode.ToMini;
            //    form = new FormMini();
            //    SettingsMgr.ApplyMiniFormSettings((Form)form);
            //}
            //else
//.........這裏部分代碼省略.........
開發者ID:JamesMcWhinney,項目名稱:inSSIDer-2,代碼行數:101,代碼來源:Program.cs

示例12: AlipayPay

        private void AlipayPay(object sender, EventArgs args)
        {


            if (!AliPayHelper.CheckConfig())
            {
                Toast.MakeText(ApplicationContext,
                    "係統異常.",
                    ToastLength.Long);
                Log.Error(Tag, "Aplipay Config Exception ");
                return;
            }
            string payInfo = AliPayHelper.GetPayInfo();
            // 完整的符合支付寶參數規範的訂單信息
            Runnable payRunnable = new Runnable(() =>
            {
                PayTask alipay = new PayTask(this);
                // 調用支付接口,獲取支付結果
                string result = alipay.Pay(payInfo);

                Message msg = new Message
                {
                    What = (int)MsgWhat.AlipayPayFlag,
                    Obj = result
                };
                _handler.SendMessage(msg);
            });

            // 必須異步調用
            Thread payThread = new Thread(payRunnable);
            payThread.Start();
        }
開發者ID:MicahelWang,項目名稱:XamarinSamples,代碼行數:32,代碼來源:PayLayout.cs

示例13: check

        /**
	 * check whether the device has authentication alipay account.
	 * 查詢終端設備是否存在支付寶認證賬戶
	 * 
	 */
        public void check(object o, EventArgs e)
        {
            Runnable checkRunnable = new Runnable(()=> {
                PayTask payTask = new PayTask(this);
                // 調用查詢接口,獲取查詢結果
                bool isExist = payTask.CheckAccountIfExist();

                Message msg = new Message();
                msg.What = SDK_CHECK_FLAG;
                msg.Obj = isExist;
                mHandler.SendMessage(msg);
            });

            Thread checkThread = new Thread(checkRunnable);
            checkThread.Start();

        }
開發者ID:MicahelWang,項目名稱:XamarinSamples,代碼行數:22,代碼來源:MainActivity.cs

示例14: pay

        public void pay(object o, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(PARTNER) || string.IsNullOrWhiteSpace(RSA_PRIVATE)
                    || string.IsNullOrWhiteSpace(SELLER))
            {
                new AlertDialog.Builder(this)
                        .SetTitle("警告")
                        .SetMessage("需要配置PARTNER | RSA_PRIVATE| SELLER")
                        .SetPositiveButton("確定", (dialoginterface, i) => { Finish(); }

                                ).Show();
                return;
            }
            // 訂單
            string orderInfo = GetOrderInfo("測試的商品", "該測試商品的詳細描述", "0.01");

            // 對訂單做RSA 簽名
            string sign = Sign(orderInfo);
            try
            {
                // 僅需對sign 做URL編碼
                sign = Java.Net.URLEncoder.Encode(sign, "UTF-8");
            }
            catch (UnsupportedEncodingException ex)
            {
                ex.PrintStackTrace();
            }
            finally
            {
                string payInfo = orderInfo + "&sign=\"" + sign + "\"&"
                                + GetSignType();
                // 完整的符合支付寶參數規範的訂單信息
                Runnable payRunnable = new Runnable(()=> {
                    PayTask alipay = new PayTask(this);
                    // 調用支付接口,獲取支付結果
                    string result = alipay.Pay(payInfo);

                    Message msg = new Message();
                    msg.What = SDK_PAY_FLAG;
                    msg.Obj = result;
                    mHandler.SendMessage(msg);
                });
                
                // 必須異步調用
                Thread payThread = new Thread(payRunnable);
                payThread.Start();
            }


        }
開發者ID:MicahelWang,項目名稱:XamarinSamples,代碼行數:50,代碼來源:MainActivity.cs

示例15: AddRef

        private static void AddRef(IntPtr ptr)
        {
#if REFDEBUG
            if (refdumper == null)
            {
                refdumper = new Thread(dumprefs);
                refdumper.IsBackground = true;
                refdumper.Start();
            }
#endif
            lock (reflock)
            {
                if (!_refs.ContainsKey(ptr))
                {
#if REFDEBUG
                    Console.WriteLine("Adding a new reference to: " + ptr + " (" + 0 + "==> " + 1 + ")");
#endif
                    _refs.Add(ptr, 1);
                }
                else
                {
#if REFDEBUG
                    Console.WriteLine("Adding a new reference to: " + ptr + " (" + _refs[ptr] + "==> " + (_refs[ptr] + 1) + ")");
#endif
                    _refs[ptr]++;
                }
            }
        }
開發者ID:christlurker,項目名稱:ROS.NET,代碼行數:28,代碼來源:XmlRpcDispatch.cs


注:本文中的System.Thread.Start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。