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


C# ThreadStart.BeginInvoke方法代码示例

本文整理汇总了C#中ThreadStart.BeginInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# ThreadStart.BeginInvoke方法的具体用法?C# ThreadStart.BeginInvoke怎么用?C# ThreadStart.BeginInvoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ThreadStart的用法示例。


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

示例1: Execute

        public void Execute(IWorker[] workers, int runningSecs)
        {
            IAsyncResult[] ar = new IAsyncResult[workers.Length];
              int i = 0;
              foreach (IWorker w in workers) {
            w.WorkerID = i;
            ThreadStart t = new ThreadStart(w.DoWork);
            ar[i++] = t.BeginInvoke(null, null);
              }
              //for (int j = 0; j < runningSecs * 10; j++)
              //{
              //    Console.Write(".");
              //    Thread.Sleep(100);
              //}
              Thread.Sleep(runningSecs * 1000);
              Console.WriteLine();

              foreach (IWorker w in workers) {
            w.Running = false;
              }

              bool timeOut = false;
              foreach (IAsyncResult a in ar) {
              if (!a.IsCompleted)
              {
              if (!a.AsyncWaitHandle.WaitOne(1000))
                  timeOut = true;
              }
              }
              if (timeOut)
              Console.WriteLine("Timed Out!");
        }
开发者ID:AveProjVstm,项目名称:MonoVstmTests,代码行数:32,代码来源:ExecutorThreadPool.cs

示例2: Run

		public void Run(string fileName, string arguments)
		{
			if (isRunning) throw new Exception("This ProcessRunner is already running a process.");
			if (!File.Exists(fileName)) throw new FileNotFoundException("The program '"+fileName+"' was not found.",fileName);

			isRunning = true;
			process = new Process();
			process.StartInfo.UseShellExecute = false;
			process.StartInfo.RedirectStandardOutput = true;
			process.StartInfo.RedirectStandardError = true;
			process.StartInfo.CreateNoWindow = true;
			process.StartInfo.FileName = fileName;
			process.StartInfo.Arguments = arguments;
			process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
			process.Start();
			
			outputReader = process.StandardOutput;
			errorReader = process.StandardError;
			
			// we need to wait for all 3 of our threadpool operations to finish
			// (processexit, readoutput, readerror)
			tasksFinished = 0;
			
			// do our waiting on the threadpool
			ThreadStart waitForExitDel = new ThreadStart(process.WaitForExit);
			waitForExitDel.BeginInvoke(new AsyncCallback(TaskFinished),null);
			
			// also read outputs on the threadpool
			ThreadStart readOutputDel = new ThreadStart(ReadOutput);
			ThreadStart readErrorDel = new ThreadStart(ReadError);
			
			readOutputDel.BeginInvoke(new AsyncCallback(TaskFinished),null);
			readErrorDel.BeginInvoke(new AsyncCallback(TaskFinished),null);
		}
开发者ID:heon21st,项目名称:flashdevelop,代码行数:34,代码来源:ProcessRunner.cs

示例3: Run

        public void Run(String fileName, String arguments, Boolean shellCommand)
		{
			if (isRunning) throw new Exception("This ProcessRunner is already running a process.");
            if (!shellCommand && !File.Exists(fileName)) throw new FileNotFoundException("The program '" + fileName + "' was not found.", fileName);

			isRunning = true;
			process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardInput = RedirectInput;
			process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.StandardOutputEncoding = Encoding.Default;
            process.StartInfo.StandardErrorEncoding = Encoding.Default;
			process.StartInfo.CreateNoWindow = true;
			process.StartInfo.FileName = fileName;
			process.StartInfo.Arguments = arguments;
            process.StartInfo.WorkingDirectory = WorkingDirectory ?? PluginBase.MainForm.WorkingDirectory;
			process.Start();
			
			outputReader = process.StandardOutput;
			errorReader = process.StandardError;
			
			// we need to wait for all 3 threadpool operations 
            // to finish (processexit, readoutput, readerror)
			tasksFinished = 0;
			
			ThreadStart waitForExitDel = new ThreadStart(process.WaitForExit);
			waitForExitDel.BeginInvoke(new AsyncCallback(TaskFinished), null);
			
			ThreadStart readOutputDel = new ThreadStart(ReadOutput);
			ThreadStart readErrorDel = new ThreadStart(ReadError);
			
			readOutputDel.BeginInvoke(new AsyncCallback(TaskFinished), null);
			readErrorDel.BeginInvoke(new AsyncCallback(TaskFinished), null);
		}
开发者ID:heon21st,项目名称:flashdevelop,代码行数:35,代码来源:ProcessRunner.cs

示例4: Run

        /**
        * Runs the specified process
        */ 
		public void Run(String fileName, String arguments)
		{
			this.isRunning = true;
            this.process = new Process();
            this.process.StartInfo.UseShellExecute = false;
            this.process.StartInfo.RedirectStandardOutput = true;
            this.process.StartInfo.RedirectStandardError = true;
            this.process.StartInfo.RedirectStandardInput = true;
            this.process.StartInfo.CreateNoWindow = true;
            this.process.StartInfo.FileName = fileName;
            this.process.StartInfo.Arguments = arguments;
            this.process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
            this.process.Start();

            this.outputReader = process.StandardOutput;
            this.errorReader = process.StandardError;
			
			// We need to wait for all 3 of our threadpool operations to finish (processexit, readoutput, readerror)
            this.tasksFinished = 0;
			
			// Do our waiting on the threadpool
			ThreadStart waitForExitDel = new ThreadStart(process.WaitForExit);
			waitForExitDel.BeginInvoke(new AsyncCallback(TaskFinished), null);
			
			// Also read outputs on the threadpool
			ThreadStart readOutputDel = new ThreadStart(this.ReadOutput);
            ThreadStart readErrorDel = new ThreadStart(this.ReadError);

            readOutputDel.BeginInvoke(new AsyncCallback(this.TaskFinished), null);
            readErrorDel.BeginInvoke(new AsyncCallback(this.TaskFinished), null);
		}
开发者ID:heon21st,项目名称:flashdevelop,代码行数:34,代码来源:ProcessRunner.cs

示例5: SingleButton

 public void SingleButton(object sender, EventArgs args)
 {
     //Create new server in new thread
     // load client gameplayscreen
     ThreadStart test = new ThreadStart(serverStart);
     test.BeginInvoke(null, null);
     ScreenManager.AddScreen(new UserInterface.Screens.GamePlayScreen("127.0.0.1", 28000));
 }
开发者ID:Tricon2-Elf,项目名称:DystopiaRPG,代码行数:8,代码来源:MainMenuScreen.cs

示例6: ThreadedWriter

        public ThreadedWriter(ILockStrategy lck)
        {
            _started = new ManualResetEvent(false);
            _complete = new ManualResetEvent(false);

            _lck = lck;
            _delegate = HoldLock;
            _async = _delegate.BeginInvoke(null, null);
            if (!_started.WaitOne(1000, false))
            {
                _delegate.EndInvoke(_async);
                Assert.Fail("Unable to acquire lock");
            }
            Assert.IsTrue(_locked);
        }
开发者ID:langimike,项目名称:CSharpTest.Net.Collections,代码行数:15,代码来源:ThreadedReaderWriter.cs

示例7: Execute

        public void Execute(IWorker[] workers, int runningSecs)
        {
            IAsyncResult[] ar = new IAsyncResult[workers.Length];
              int i = 0;
              foreach (IWorker w in workers) {
            ThreadStart t = new ThreadStart(w.DoWork);
            ar[i++] = t.BeginInvoke(null, null);
              }
              /*
              for (int j = 0; j < runningSecs*10; j++) {
            Console.Write(".");
            Thread.Sleep(100);
              }*/
              Thread.Sleep(runningSecs * 1000);
              Console.WriteLine("--------------- Time running finished!!!!");

              foreach (IWorker w in workers) {
            w.Running = false;
              }
              foreach (IAsyncResult a in ar) {
            if (!a.IsCompleted) a.AsyncWaitHandle.WaitOne();
              }
        }
开发者ID:AveProjVstm,项目名称:MonoVstmTests,代码行数:23,代码来源:ExecutorThreadPool.cs

示例8: Start

 public void Start()
 {
     thread = new ThreadStart(QueryFrame);
     IsRunning = true;
     thread.BeginInvoke(null, null);
 }
开发者ID:Iridio,项目名称:XNAFaceDetection,代码行数:6,代码来源:VideoEmgu.cs

示例9: LoadFoundstoneXsmlAdds

        private void LoadFoundstoneXsmlAdds()
        {
            string strPathToLocalCopyOfXmlFile = Path.Combine(MapPath("~/xml/"),"info.xml");
            string strSourceInformation = "";
            try
            {
                string strTest = Session["FoundstoneMaketingMaterial"].ToString();
                if (Session["FoundstoneMaketingMaterial"].ToString()=="")
                {
                    // return;	// comment here to disable this test
                    XPathDocument myXPathDoc;
                    // we are going to start a new thread and give it 500ms to complete (this is thread we open a TCP connection to www.foundstone.com)
                    bAreWeOnline = false;
                    ThreadStart tsAreWeOnline = new ThreadStart(checkIfWeAreOnline);
                    tsAreWeOnline.BeginInvoke(null,null);
                    Thread.Sleep(500);
                    if (bAreWeOnline)				// if the tcp connection was succssfull we are online
                    {
                        //Response.Write("<hr/> We are online <hr/>");
                        myXPathDoc = new XPathDocument(strPathToWebCopyXmlFile);
                        strSourceInformation = "&nbsp;&nbsp;&nbsp;<i>[The information below is up-to-date and was downloaded from the foundstone website]</i><br>";
                    }
                    else
                    {
                        //Response.Write("<hr/> We are NOT online <hr/>");
                        myXPathDoc = new XPathDocument(strPathToLocalCopyOfXmlFile);
                        strSourceInformation = "&nbsp;&nbsp;&nbsp;<i>[ The current computer is not online, so the information below might be out-of-date]</i><br>";
                    }

                    // now that we have a file to work on (either the dynamic from the website of the one local) we can can do the transformation
                    XslTransform myXslTrans = new XslTransform() ;
                    myXslTrans.Load(Path.Combine(MapPath(Gui.pathToXslFolder),"info.xsl"));
                    MemoryStream msXslTrans = new MemoryStream();
                    myXslTrans.Transform(myXPathDoc,null,msXslTrans, new XmlUrlResolver()) ;
                    msXslTrans.Flush();
                    msXslTrans.Position= 0;
                    // after store the transformation in a session variable so that we don't have to do this everytime
                    Session["FoundstoneMaketingMaterial"] =  (new StreamReader(msXslTrans)).ReadToEnd();
                }
                lbXmlInformation.Text = strSourceInformation + Session["FoundstoneMaketingMaterial"].ToString();
            }
            catch (Exception ex)
            {
                Response.Write("<hr/>LoadFoundstoneXsmlAdds: " + ex.Message + "<hr/>");
            }
        }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:46,代码来源:Login.aspx.cs

示例10: SetupAsync

        public void SetupAsync()
        {
            if (IsBusy) return;

            this.dataGridViewUpdates.Rows.Clear();
            releases = null;
            timerImgAnimate.Start();

            this.Invalidate();
            this.Refresh();

            ThreadStart ts = new ThreadStart(SetupAndBuildReleaseList);
            asyncres = ts.BeginInvoke(new AsyncCallback(SetupAsyncCompleted), null);
        }
开发者ID:nguyenhuuhuy,项目名称:mygeneration,代码行数:14,代码来源:ApplicationReleasesControl.cs

示例11: SendMailAsync

        /// <summary>
        /// Fully self contained method that sends email by just sending
        /// without waiting for confirmation by starting a new thread
        /// </summary>
        /// <returns></returns>
        public void SendMailAsync()
        {
            ThreadStart oDelegate = new ThreadStart(SendMailRun);
            //			Thread myThread = new Thread(oDelegate);
            //			myThread.Start();

            /// If you want to use the Thread Pool you can just use a delegate
            /// This will often be faster and more efficient especially for quick operations
            oDelegate.BeginInvoke(null, null);
        }
开发者ID:jackiechou,项目名称:thegioicuaban.com,代码行数:15,代码来源:SmtpClientCustom.cs

示例12: Form1_Load

        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (string name in names)
            {
                ToolStripMenuItem tsi = new ToolStripMenuItem(name);
                tsi.Click += ToolStripMenuItem_Click;
                contextMenuStrip1.Items.Add(tsi);
            }

            if (!File.Exists(strDownloadPath + "\\trainedImages.xml"))
                return;
            string xml = File.ReadAllText(strDownloadPath + "\\trainedImages.xml");
            trainedFaces = (SeDes.ToObj(xml, trainedFaces) as List<trainedFace>);
            ThreadStart ts = new ThreadStart(fixFaces);
            progressBar1.Visible = true;

            IAsyncResult iar = ts.BeginInvoke((AsyncCallback) =>
            {
                this.Invoke((MethodInvoker)delegate
                {
                    progressBar1.Visible = false;
                });
            }, null);
            

        }
开发者ID:Hagser,项目名称:csharp,代码行数:26,代码来源:Form1.cs

示例13: cmdBeClient_Click

 private void cmdBeClient_Click(object sender, System.EventArgs e)
 {
     //***********************  Client Attempt ******************************************
     //amIClient = true;
     cmdFindClients.Enabled = false;
     ThreadStart myThreadStart = new ThreadStart(client);
     System.IAsyncResult m = null;
     m = myThreadStart.BeginInvoke(new AsyncCallback(caller),null);
 }
开发者ID:keithloughnane,项目名称:CowsWithGuns,代码行数:9,代码来源:frmGameStart.cs

示例14: button1_Click_1

 private void button1_Click_1(object sender, System.EventArgs e)
 {
     //start a new thread running doServerStuff()
     ThreadStart myThreadStart = new ThreadStart(doServerStuff);
     System.IAsyncResult m = null;
     m = myThreadStart.BeginInvoke(new AsyncCallback(caller),null);
 }
开发者ID:keithloughnane,项目名称:CowsWithGuns,代码行数:7,代码来源:frmGameStart.cs

示例15: LoadAsync

		public void LoadAsync ()
		{
			if (load_completed)
				return;
			ThreadStart async = new ThreadStart (Load);
			async.BeginInvoke (AsyncFinished, async);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:SoundPlayer.cs


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