- [C#] BackgroundWorker 範例1
- [C#] BackgroundWorker 範例2
- [C#] BackgroundWorker 範例3
- [C#] BackgroundWorker 範例4
- [C#] BackgroundWorker - Exception
星期五, 2月 24, 2017
[C#] BackgroundWorker
四篇筆記
星期四, 2月 23, 2017
[C#] BackgroundWorker 範例4
閱讀這篇 MSDN 文章 如何:在背景中下載檔案,發現兩個重點
在 RunWorkerCompletedEventArgs.Result 內也有相關說明
請務必檢查您 RunWorkerCompleted 事件處理常式中的 AsyncCompletedEventArgs.Error 屬性,再嘗試存取可能會受 DoWork 事件處理常式影響的 RunWorkerCompletedEventArgs.Result 屬性或任何其他物件。XXXEventArgs 通常都是 Event 第二參數,RunWorkerCompleted Event 明明就是 RunWorkerCompletedEventArgs,只能自行解讀為要先判斷 RunWorkerCompletedEventArgs.Cancel 和 RunWorkerCompletedEventArgs.Error,再來存取 RunWorkerCompletedEventArgs.Result
在 RunWorkerCompletedEventArgs.Result 內也有相關說明
您 RunWorkerCompleted 事件處理常式應該一律檢查 Error 和 Cancelled 屬性,然後再存取 Result 屬性。 如果發生例外狀況,或已取消作業,存取 Result 屬性引發例外狀況。Application.DoEvents 的存在,可以讓迴圈進行時,UI 還可以進行操作,但該作法會造成 CPU 飆高,所以要利用 Thread.Sleep 睡一下,該效果透過工作管理員就可以觀察到
while (this.backgroundWorker1.IsBusy)
{
progressBar1.Increment(1);
// Keep UI messages moving, so the form remains
// responsive during the asynchronous operation.
Application.DoEvents();
// 避免 CPU 飆高
Thread.Sleep(1);
}
星期日, 2月 19, 2017
星期六, 2月 18, 2017
[C#] BackgroundWorker 範例2
閱讀該篇 MSDN 文章 - BackgroundWorker 類別 並記錄,該文章是利用迴圈和 Tread.Sleep 來產生耗時操作,藉此來學習 BackgroundWorker
WinForm layout
WinForm layout
星期五, 2月 17, 2017
[C#] BackgroundWorker 範例1
閱讀該篇 MSDN 文章 - Walkthrough: Multithreading with the BackgroundWorker Component (C#) 並記錄,該文章是利用讀取 txt 檔案並統計其關鍵字,藉此介紹 BackgroundWorker 功能
Solution 檔案
WinForm Layout
Solution 檔案
WinForm Layout
星期五, 2月 10, 2017
[VSTS] Git command reference - Undo
了解該篇文章 Git command reference 的 Undo 說明並記錄
目的:Revert all changes and roll back to the most recent commit
git 語法:git reset --hard HEAD
Team Explorer 畫面:
目的:Revert all changes and roll back to the most recent commit
git 語法:git reset --hard HEAD
Team Explorer 畫面:
星期四, 2月 09, 2017
[VSTS] Git command reference - Merge and rebase
了解該篇文章 Git command reference 的 Merge and rebase 說明並記錄
目的:Merge a branch into the current branch
git 語法:git merge branchname In the Team Explorer Branches view, right-click the branch you want to
Team Explorer 畫面:
目的:Merge a branch into the current branch
git 語法:git merge branchname In the Team Explorer Branches view, right-click the branch you want to
Team Explorer 畫面:
星期三, 2月 08, 2017
[VSTS] Git command reference - Sync changes
了解該篇文章 Git command reference 的 Sync changes 說明並記錄
目的:Download new branches and commits from a remote repo, but do not merge them into your local branches
git 語法:git fetch
Team Explorer 畫面:
目的:Download new branches and commits from a remote repo, but do not merge them into your local branches
git 語法:git fetch
Team Explorer 畫面:
星期二, 2月 07, 2017
[VSTS] Git command reference - Compare files and versions
了解該篇文章 Git command reference 的 Compare files and versions 說明並記錄
目的:Compare the current contents of a singile file and the contents in the last commit
git 語法:git diff HEAD filename
Team Explorer 畫面:
目的:Compare the current contents of a singile file and the contents in the last commit
git 語法:git diff HEAD filename
Team Explorer 畫面:
星期一, 2月 06, 2017
[VSTS] Git command reference - Commits
了解該篇文章 Git command reference 的 Commits 說明並記錄
目的:Create a new commit
git 語法:git commit -m "message"
Team Explorer 畫面:
目的:Create a new commit
git 語法:git commit -m "message"
Team Explorer 畫面:
星期日, 2月 05, 2017
[VSTS] Git command reference - Branches
了解該篇文章 Git command reference 的 Branches 說明並記錄
目的:Create a new branch
git 語法:git branch branchname
Team Explorer 畫面:
目的:Create a new branch
git 語法:git branch branchname
Team Explorer 畫面:
星期四, 2月 02, 2017
[VSTS] Git command reference - Repos
了解該篇文章 Git command reference 的 Repos 說明並記錄
目的:Create a repo in a new folder
git 語法:git init foldername
Team Explorer 畫面:
目的:Create a repo in a new folder
git 語法:git init foldername
Team Explorer 畫面: