星期四, 2月 23, 2017

[C#] BackgroundWorker 範例4

閱讀這篇 MSDN 文章 如何:在背景中下載檔案,發現兩個重點
請務必檢查您 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

[C#] BackgroundWorker 範例3

閱讀該篇 MSDN 文章 - 逐步解說:實作使用背景作業的表單 並記錄,該文章是利用 Fibonacci 來產生耗時操作,藉此來學習 BackgroundWorker

WinForm layout

[C#] BackgroundWorker - Fibonacci-1

星期六, 2月 18, 2017

[C#] BackgroundWorker 範例2

閱讀該篇 MSDN 文章 - BackgroundWorker 類別 並記錄,該文章是利用迴圈和 Tread.Sleep 來產生耗時操作,藉此來學習 BackgroundWorker

WinForm layout

[C#] BackgroundWorker 簡易範例-1

星期五, 2月 17, 2017

[C#] BackgroundWorker 範例1

閱讀該篇 MSDN 文章 - Walkthrough: Multithreading with the BackgroundWorker Component (C#) 並記錄,該文章是利用讀取 txt 檔案並統計其關鍵字,藉此介紹 BackgroundWorker 功能

Solution 檔案

WalkthroughBackgroundWorker-1

WinForm Layout

WalkthroughBackgroundWorker-2

星期五, 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 畫面:

[VSTS] Git command reference-Undo-01

星期四, 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 畫面:

[VSTS] Git command reference - Merge and rebase - 11

[VSTS] Git command reference - Merge and rebase - 12

星期三, 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 畫面:

[VSTS] Git command reference - Sync changes-1

星期二, 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 畫面:

[VSTS] Git command reference-Compare files and versions-01

星期一, 2月 06, 2017

[VSTS] Git command reference - Commits

了解該篇文章 Git command reference 的 Commits 說明並記錄

目的:Create a new commit
git 語法:git commit -m "message"
Team Explorer 畫面:

[VSTS] Git command reference - Commits-01

星期日, 2月 05, 2017

[VSTS] Git command reference - Branches

了解該篇文章 Git command reference 的 Branches 說明並記錄

目的:Create a new branch
git 語法:git branch branchname
Team Explorer 畫面:

[VSTS] Git command reference-Branches-01

星期四, 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 畫面:

[VSTS] Git command reference-repos-01-git init