WinFormÖнøÐи´ÔӵIJÙ×÷ÍùÍù»áµ¼Ö½çÃæ¼ÙËÀ£¬ÕâÖÖÇé¿öÒ»°ãÓû§ÍùÍù»áÔٵ㼸ÏÂo(¦á¦ä¦á)o¡£¸üºÃµÄ·½·¨ÊÇʵÏÖ½çÃæ²Ù×÷Óëºǫ́²Ù×÷µÄÒì²½·½ ʽ£¬µ±È»Ê¹ÓöàÏß³ÌÒ²¿ÉÒÔ£¬ÕâÀï½éÉܵÄÊÇ.net frameworkÖÐÌṩµÄ×Ô´ø¿Ø¼þBackgroundWorker¡£Ëü¾ÍÊÇʵÏÖ½çÃæ²Ù×÷Óëºǫ́²Ù×÷Òì²½Ö´ÐеĿؼþ£¬ËüµÄÖ÷ÒªÔÀíÊÇ´´½¨Á½¸ö»òÁ½¸öÒÔÉÏ µÄỊ̈߳¬ÆäÖнçÃæÀàΪÖ÷Ị̈߳¬ÆäËûΪ¸¨ÖúỊ̈߳¬Ò²¾ÍÊǺǫ́´¿ÖÖ£¬Ëü¿ÉÒÔÔÚÖ÷Ïß³ÌÓ븨ÖúÏß³ÌÖÐʵÏÖͨѶ£¬ÕâÑù¾ÍʵÏÖÁ˺ǫ́²Ù×÷½ø¶ÈËæʱ·´Ó¦¸øÓû§ÖªµÀ¡£
ÆäÖ÷ÒªÊôÐÔÓÐÁ½¸ö£¬ Ò»ÊÇWorkReportsProgress£¬´ú±í״̬¸Ä±äÊÇ·ñ±¨¸æ½ø¶È£¬ÎÒÃÇ°²×°Èí¼þÖг£¼ûµÄ½ø¶È¶È¾Í¿ÉÒÔÓÉËüÀ´¿ØÖÆ¡£¶þÊÇWorkSupportsCancel£¬´ú±íÏß³ÌÊÇ·ñÖ§³ÖÈ¡Ïû£¬Èç¹û²»Ö§³ÖµÄ»°£¬ÄÇÖ»ÓÐÒ»Ö±µÈ´ý³ÌÐòÔËÐнáÊøÁË¡£
ÆäʼþÖ÷ÒªÓÐÈý¸ö£ºDoWorkΪ×îÖ÷ÒªµÄʼþ£¬Ëù½øÐеIJÙ×÷Ò²¾ÍÔÚÕâÀïÖ´ÐУ»ProgressChanged´ú±í¸¨ÖúÏ̷߳¢Éú¸Ä±äʱִÐеÄʼþ£¬Ò»°ã½ø¶ÈÌõ¾ÍÊÇÔÚÕâÀï¸Ä±äµÄ£»RunWorkerCompleted´ú±í¸¨ÖúÏß³ÌÖ´ÐÐÍê³É½øÐеIJÙ×÷¡£
Æô¶¯Ïß³ÌʹÓÃRunWorkerAsync·½·¨¡£
////// µã»÷ /// /// /// private void btnRun_Click(object sender, EventArgs e) { if (backgroundWorker.IsBusy) { MessageBox.Show("³ÌÐòÕý棬ÇëÄÍÐĵȴý", "ÔËÐÐÌáʾ", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { backgroundWorker.RunWorkerAsync(textUrl.Text); } } ////// Ö÷³ÌÐò /// /// /// private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bw = (BackgroundWorker)sender; string url = e.Argument.ToString(); for (int i = 0; i < 10; i++) { if (!bw.CancellationPending) { webBrowser.Url =new Uri( url); Thread.Sleep(1000); bw.ReportProgress(i * 100 / 10, i); } } } ////// ״̬¸Ä±ä /// /// /// private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { progressBar.Value = e.ProgressPercentage; lblStatus.Text ="µÚ" + e.UserState.ToString() + "´ÎÔËÐÐ"; } ////// ½áÊø /// /// /// private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { lblStatus.Text = "³ÌÐòÔËÐнáÊø"; }
ÍƼöÐÅÏ¢
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- Asp.net MVCÔ´Âë·ÖÎö--Model Validation(Se....
- .Net À¬»ø»ØÊÕ»úÖÆÔÀíºÍËã·¨£¨Ò»£©
- .netʵÌåнâ
- ·ÖÎöASP.NET¶ÁÈ¡XMLÎļþ4ÖÖ·½·¨
- »ñÈ¡ÍøÕ¾ËõÂÔͼ´úÂë
- Asp.net ¸ù¾ÝIPµØÖ·»ñÈ¡¿çÍø¶ÎmacµØÖ·º¯Êý¡¾ËѲء¿
- ¹ýÂËÃô¸Ð¹Ø¼ü×Ö¡£
- Éú³ÉÖ¸¶¨Î»ÊýµÄËæ»ú×Ö·û´®
- ¿Í»§¶Ë»ñÈ¡MACµØÖ·£¬µ½·þÎñÆ÷ÑéÖ¤
- ²½²½ÎªÓª .NETÈý²ã¼Ü¹¹½âÎö ¶þ¡¢Êý¾Ý¿âÉè¼Æ
ÆÀÂÛ