当前位置: 首页>>代码示例>>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;未经允许,请勿转载。