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

C# ParameterizedThreadStart类代码示例

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

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



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


示例16: Calculate

        public void Calculate(String filepath)
        {
            this.Show();

            try
            {
                if (File.Exists(filepath))
                {
                    FileInfo fi = new FileInfo(filepath);
                    FileSize fs = new FileSize(fi.Length);

                    lblStatus.Text = "Calculating MD5... (For large files this may take a while)";
                    lblFilename.Text = filepath;
                    lblFileSize.Text = fs.ToString();

                    ParameterizedThreadStart pt = new ParameterizedThreadStart(GetMD5);
                    Thread t = new Thread(pt);
                    t.Start(filepath);
                }
                else
                {
                    this.Close();
                    MessageBox.Show("File does not exist.");
                    Application.Exit();
                }
            }
            catch (Exception)
            {
                // If an exception is thrown, it's likely that the file is in use.
                MessageBox.Show("File is currently in use by another application.");
                Application.Exit();
            }
        }
开发者ID:Rychard,项目名称:MD5Helper,代码行数:33,代码来源:SplashForm.cs


示例17: count_Click

        private void count_Click(object sender, EventArgs e)
        {
            string text = string.Empty;
            if (rbCopyPaste.Checked)
                text = content.Text;
            else
            {
                openFileDialog1.Filter = "Arquivos do Word (*.doc)|*.doc|Arquivos texto(*.txt)|*.txt|Arquivos rich text(*.rtf)|*.rtf";
                DialogResult result = openFileDialog1.ShowDialog();

                if (result != System.Windows.Forms.DialogResult.OK)
                    return;

                using (StreamReader reader = new StreamReader(openFileDialog1.FileName))
                {
                    text = reader.ReadToEnd();
                }
            }

            ParameterizedThreadStart pts = new ParameterizedThreadStart(StartWordGathering);
            Thread t = new Thread(pts);
            t.Start(text);

            //WordList wordList = GetHash(text);
            //ListByWordCount(wordList);
        }
开发者ID:arturcp,项目名称:Word-Occurencies,代码行数:26,代码来源:Form1.cs


示例18: WriteRecordBySquadId

 /// <summary>
 /// Write record for squad i in XML file
 /// </summary>
 /// <param name="id">Squad ID. Defferent with IndexId which starts with zero</param>
 /// <param name="record">String to write into XML element</param>
 public static void WriteRecordBySquadId(int id, String record)
 {
     ParameterizedThreadStart p = new ParameterizedThreadStart(WriteRecordBySquadId);
     Thread writeThread = new Thread(p);
     ThreadParams threadParams = new ThreadParams(id, record, syncObject);
     writeThread.Start(threadParams);
 }
开发者ID:Dracontis,项目名称:Ratings,代码行数:12,代码来源:Ratings.cs


示例19: connect

        /// <summary>
        /// 连接服务器方法,循环创建线程用于连接每台服务器
        /// </summary>
        /// <param name="ObjIp">传入的Ip对象集合</param>
        public void connect(object ObjIp)
        {
            List<ClientInfo> IpAndport = (List<ClientInfo>)ObjIp;

            for (int i = 0; i < IpAndport.Count; i++)
            {
                IsApplyRetry.Add(IpAndport[i].Ip,false);
                ManualResetEvent ConnectTimeout = new ManualResetEvent(false);
                DictTimeoutObject.Add(IpAndport[i].Ip, TimeoutObject);
                ManualResetEvent SendTimeout = new ManualResetEvent(false);
                DictSendoutObject.Add(IpAndport[i].Ip, SendTimeout);
                ManualResetEvent RecTimeout = new ManualResetEvent(false);
                DictRecoutObject.Add(IpAndport[i].Ip, RecTimeout);

                ParameterizedThreadStart pts = new ParameterizedThreadStart(AloneConnect);
                Thread thradRecMsg = new Thread(pts);
                thradRecMsg.IsBackground = true;
                thradRecMsg.Start(IpAndport[i]);
            }
            ParameterizedThreadStart p = new ParameterizedThreadStart(Testonline);
            Thread testonline = new Thread(p);
            testonline.IsBackground = true;
            testonline.Start(IpAndport);

            ParameterizedThreadStart handlemessage = new ParameterizedThreadStart(HandleMessage);
            Thread handle = new Thread(handlemessage);
            handle.IsBackground = true;
            handle.Start();
        }
开发者ID:konglinghai123,项目名称:SocketWatcher,代码行数:33,代码来源:Client.cs


示例20: GetSource

        protected override void GetSource( Envelope extent, int width, int height, DynamicLayer.OnImageComplete onComplete )
        {
            _currentWidth = width;
            _currentHeight = height;

            MapPoints = new List<MapPoint>();

            //Make up some dummy data
            int count = 0;
            while( count < 1000 )
            {
                MapPoints.Add( new MapPoint( extent.XMin + ( extent.Width * ( _random.Next( 100 ) / 100.00 ) ),
                    extent.YMin + ( extent.Height * ( _random.Next( 100 ) / 100.00 ) ),
                    extent.SpatialReference ) );
                count++;
            }
            //Make up some dummy data

            _pngRenderer = new PixelPngRenderer( _currentWidth, _currentHeight, MapPoints );

            ParameterizedThreadStart starter = new ParameterizedThreadStart( ( pngRenderer ) =>
            {
                Stream imageStream = InitalizeImage( pngRenderer as PixelPngRenderer );

                Dispatcher.BeginInvoke( () =>
                {
                    _image = new BitmapImage();
                    _image.SetSource( imageStream );
                    onComplete( _image, width, height, extent );
                } );
            } );
            new Thread( starter ).Start( _pngRenderer );
        }
开发者ID:OliveiraThales,项目名称:GeoCache,代码行数:33,代码来源:PixelLayer.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Parameters类代码示例发布时间:2022-05-24
下一篇:
C# ParameterValues类代码示例发布时间: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