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


C# ParameterizedThreadStart类代码示例

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


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

示例1: ExecAsync

 public static Thread ExecAsync(ParameterizedThreadStart start, object state)
 {
     Thread _th = new Thread(start);
     _th.IsBackground = true;
     _th.Start(state);
     return _th;
 }
开发者ID:wykoooo,项目名称:copy-dotnet-library,代码行数:7,代码来源:Threads.cs

示例2: CreateThread

        /// <summary>
        /// Creates a thread.
        /// </summary>
        /// <param name="name">The name of the thread.</param>
        /// <param name="proc">The procedure to run in the thread.</param>
        /// <returns>
        /// The thread
        /// </returns>
        public Thread CreateThread(string name, ParameterizedThreadStart proc)
        {
            var t = new Thread(proc);
            t.Name = name;

            return t;
        }
开发者ID:jdeter14,项目名称:game1,代码行数:15,代码来源:ThreadFactory.cs

示例3: _StartACountingThread

 private static void _StartACountingThread(string threadName)
 {
     var parameterizedThreadStart = new ParameterizedThreadStart(_SharedCount);
     var threadOne = new Thread(parameterizedThreadStart);
     threadOne.IsBackground = false;
     threadOne.Start(threadName);
 }
开发者ID:eyecat,项目名称:Jiggler,代码行数:7,代码来源:Program.cs

示例4: MultipleThreads

        public void MultipleThreads()
        {
            GenericListener myListener = new GenericListener();
            ManualResetEvent ev = new ManualResetEvent(false);
            ArrayList threads = new ArrayList();
            System.Diagnostics.Trace.Listeners.Add(myListener);

            for (int i = 0; i < 20; i++)
            {
                ParameterizedThreadStart ts = new ParameterizedThreadStart(MultipleThreadsWorker);
                Thread t = new Thread(ts);
                threads.Add(t);
                t.Start(ev);
            }
            // now let the threads go
            ev.Set();

            // wait for the threads to end
            int x = 0;
            while (x < threads.Count)
            {
                while ((threads[x] as Thread).IsAlive)
                    Thread.Sleep(50);
                x++;
            }
        }
开发者ID:noahvans,项目名称:mariadb-connector-net,代码行数:26,代码来源:Threading.cs

示例5: PasswordDismisser

        public PasswordDismisser(string password)
        {
            ParameterizedThreadStart workerStart = new ParameterizedThreadStart(DismissPasswordDialog);
            Thread WorkerThread = new Thread(workerStart);
			WorkerThread.Name = MethodBase.GetCurrentMethod().DeclaringType.Name + "." + MethodBase.GetCurrentMethod().Name;
			WorkerThread.Start(password);
        }
开发者ID:killbug2004,项目名称:WSProf,代码行数:7,代码来源:PasswordDismisser.cs

示例6: btn_start_Click

        private void btn_start_Click(object sender, EventArgs e)
        {
            //线程更新窗体内容
            _thread = new Thread(new ThreadStart(set_txt));
            _thread.Start();

            //线程传递参数
            ParameterizedThreadStart start = new ParameterizedThreadStart(set_txt);
            Thread thread = new Thread(start);
            object obj = "From Thread With Pareameter:Hello ParameterizedThreadStart!!! ";
            thread.Start(obj);

            Thread thread2 = new Thread(() => set_txt("From Thread With Lambda:Hello Lam!!!"));
            thread2.Start();

            ThreadPool.SetMaxThreads(100, 50);
            ThreadPool.QueueUserWorkItem(set_txt, "From Thread With ThreadPool:Hello ThreadPool!!!");

            //传递BsonDocument
            BsonDocument doc_input = new BsonDocument();
            doc_input.Add("sleep", 700);
            doc_input.Add("txt", "From BsonDocument!!!");

            ParameterizedThreadStart start3 = new ParameterizedThreadStart(set_txt_with_doc);
            Thread thread3 = new Thread(start3);
            object obj3 = (object)doc_input;
            thread3.Start(obj3);

            //异步调用
            D_Add handler = new D_Add(f_add);
            sb.AppendLine("Start Add!!");
            IAsyncResult result = handler.BeginInvoke(1, 2, new AsyncCallback(f_complete), "AsycState:OK");
            sb.AppendLine("Start do other work!!");
            this.txt_result.Text = sb.ToString();
        }
开发者ID:topomondher,项目名称:web_helper,代码行数:35,代码来源:frm_thread.cs

示例7: WaysToStartThreads

        public static void WaysToStartThreads()
        {
            // 1
            // Passing the name of the method name to be executed in the ctor directly without using ThreadStart
            var thread1 = new Thread(DoSomeWork);
            thread1.Start();

            // 2
            // Passing the ThreadStart delegate  which points to a method name to be executed
            var threadStart = new ThreadStart(DoSomeWork);
            var thread2 = new Thread(threadStart);
            thread2.Start();

            // 3
            // Passing the ParametrizedThreadStart delegate  which points to a method to be executed
            var parametrizedThreadStart = new ParameterizedThreadStart(DoSomeWorkWithParameter);
            var thread3 = new Thread(parametrizedThreadStart);
            thread3.Start(2);

            // 4
            // Passing a Lambda expression in the Thread class constructor and subsequently calling the Start method
            var thread4 = new Thread(() =>
            {
                int x = 5;
                for (int i = 0; i < x; i++)
                {
                    Console.WriteLine(i);
                }
            });

            thread4.Start();

            // 5
            // Leveraging ThreadPools, call ThreadPool.QueueUserWorkItem passing in the method name to be executed
            ThreadPool.QueueUserWorkItem(DoSomeWorkWithParameter);
            ThreadPool.QueueUserWorkItem(DoSomeWorkWithParameter, 4);

            // 6
            // Using TPL (Task Parallel Library). Create a Task<T>, where T is the return type of the method to be executed.
            Task<string> task = Task.Factory.StartNew<string>(DoSomeStringWork);
            var result = task.Result;

            // 7
            // Using Asynchronous Delegates
            Func<string, string> work = DoSomeStringWork;
            IAsyncResult res = work.BeginInvoke("Hello", null, null);
            string result1 = work.EndInvoke(res);

            ////TODO: Explicit use of Thread class

            //Threadpool

            //Task Parallel Library

            //Action class with lambda functions

            //BeginInvoke

            //BackgroundWorker
        }
开发者ID:SaurabhNijhawan,项目名称:CSharpAlgorithmsAndDataStructures,代码行数:60,代码来源:Program.cs

示例8: WatchConnecting

        /// <summary>
        /// 连接客户端
        /// </summary>
        private  void WatchConnecting()
        {
            while (true)//持续不断的监听客户端的请求
            {
                //开始监听 客户端连接请求,注意:Accept方法,会阻断当前的线程
                Socket connection = socketWatch.Accept();
                if (connection.Connected && !dict.ContainsKey(connection.RemoteEndPoint.ToString().Substring(0, connection.RemoteEndPoint.ToString().IndexOf(":"))))
                {
                    //向列表控件中添加一个客户端的Ip和端口,作为发送时客户的唯一标识
                    // listbOnline.Items.Add(connection.RemoteEndPoint.ToString());
                    //将与客户端通信的套接字对象connection添加到键值对集合中,并以客户端Ip做为健

                    //list.Items.Add("IP地址", connection.RemoteEndPoint.ToString());
                    string[] str = new string[]{
                        "客户端在线",
                      connection.RemoteEndPoint.ToString().Substring(0, connection.RemoteEndPoint.ToString().IndexOf(":"))
                    };
                    uishow.ShwMsgforView(list, str);
                    dict.Add( connection.RemoteEndPoint.ToString().Substring(0, connection.RemoteEndPoint.ToString().IndexOf(":")), connection);

                    //创建通信线程
                    ParameterizedThreadStart pts = new ParameterizedThreadStart(RecMsg);
                    Thread thradRecMsg = new Thread(pts);
                    thradRecMsg.IsBackground = true;
                    thradRecMsg.Start(connection);

                }
              
            }
        }
开发者ID:konglinghai123,项目名称:SocketWatcher,代码行数:33,代码来源:Server.cs

示例9: ShowHTML

 /// <summary>
 /// creates a new browser instance and displays a given html code
 /// </summary>
 /// <param name="html">the html code to display</param>
 public static void ShowHTML(string html)
 {
     ParameterizedThreadStart threadStart = new ParameterizedThreadStart(CreateBrowserAndShowIt);
     Thread thread = new Thread(threadStart);
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start(html);
 }
开发者ID:yacoub123,项目名称:android-reverse-exploit-shell,代码行数:11,代码来源:ARESBrowser.cs

示例10: recordToolStripMenuItem_Click

        private void recordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Select s =r== null?new Select():new Select(r);
            recordToolStripMenuItem.Enabled = false;
            if (s.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                recordToolStripMenuItem.Enabled = true;
                return;
            }
            r = s.recData;
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                r.path = saveFileDialog1.FileName;
            }
            else
            {
                recordToolStripMenuItem.Enabled = true;
                return;
            }
            recordToolStripMenuItem.Enabled = true;

            ParameterizedThreadStart pts = null;
            recorder = RecorderFactory.CreateRecorder(Path.GetExtension(r.path).ToLower());
            pts = new ParameterizedThreadStart(recorder.Record);
            Thread t = new Thread(pts);
            t.Start(r);
            recordToolStripMenuItem.Enabled = false;
            stopToolStripMenuItem.Enabled = true;
            pauseToolStripMenuItem.Enabled = true;
        }
开发者ID:kashwaa,项目名称:Capture,代码行数:30,代码来源:Capture.cs

示例11: Run

 public static void Run(ParameterizedThreadStart whatToRun, object param)
 {
     InheritedContextThreadRunner runner = new InheritedContextThreadRunner(whatToRun);
     Thread thread = new Thread(new ParameterizedThreadStart(runner.Run));
     thread.IsBackground = true;
     thread.Start(param);
 }
开发者ID:5509850,项目名称:baumax,代码行数:7,代码来源:InheritedContextAsyncStarter.cs

示例12: chkdsk_Click

 private void chkdsk_Click(object sender, EventArgs e)
 {
     //docmd("chkdsk.exe", disk + ":");
     ParameterizedThreadStart p = new ParameterizedThreadStart(docmd2);
     IAsyncResult i=p.BeginInvoke(new string[] { "chkdsk", disk + ":" }, null, null);
     //p.EndInvoke(i);
 }
开发者ID:WeslieRoco,项目名称:Roco_Shell,代码行数:7,代码来源:frmDisk.cs

示例13: Add

 /// <summary>
 /// Adds the specified name.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="threadSt">The thread st.</param>
 /// <param name="mLine">The m line.</param>
 public void Add(string name, ParameterizedThreadStart threadSt, Graphics mLine)
 {
     Thread trd = new Thread(threadSt);
     trd.Name = name;
     threads.Add(trd);
     trd.Start(mLine);
 }
开发者ID:WilliamPring,项目名称:SET,代码行数:13,代码来源:ThreadRepository.cs

示例14: Invoke

 public void Invoke(ParameterizedThreadStart func)
 {
     Thread thread = new Thread(func);
     thread.IsBackground = true;
     thread.Start();
     threadList.Add(thread);
 }
开发者ID:liguifa,项目名称:VMM,代码行数:7,代码来源:SmartThread.cs

示例15: Main

        static void Main()
        {
            int[] inputValues = new int[2];

            Program p = new Program();
            Calculator c = new Calculator();

            // Get first numeric value.
            inputValues[0] = p.GetNumericValue();

            // Get second numeric value.
            inputValues[1] = p.GetNumericValue();

            // TODO: Create an instance of the ParameterizedThreadStart delegate
            //      passing in the Add method of the Calculator class.
            ParameterizedThreadStart parameterizedThreadStart = new ParameterizedThreadStart(c.Add);

            // TODO: Declare and create an instance of the secondary thread
            //      passing in the delegate instance.
            Thread thread = new Thread(parameterizedThreadStart);
            //Thread thread = new Thread(c.Add);

            //TODO:  Start the secondary thread passing in the object data.
            thread.Start(inputValues);

            System.Threading.Thread.Sleep(2500);

            Console.WriteLine("\nTotal values: {0}",
                c.TotalValue);

            Console.Write("\nPress any key to end.");
            Console.ReadLine();
        }
开发者ID:Meowse,项目名称:student1,代码行数:33,代码来源:Program.cs


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