Last active
August 29, 2015 14:26
-
-
Save iyevhen/5186dd6623b6538ebe43 to your computer and use it in GitHub Desktop.
Progress which doesn't throw exceptions for invalid input parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Progress(long current, long total) | |
{ | |
if (InvokeRequired) | |
{ | |
BeginInvoke(new Action<long, long>(Progress), current, total); | |
} | |
else | |
{ | |
if (total <= 0 || current <= 0) | |
{ | |
progressBar1.Value = 0; | |
} | |
else | |
{ | |
progressBar1.Maximum = 100; | |
if (current > total) | |
current = total; | |
var percent = Convert.ToInt32((current / new decimal(total)) * 100); | |
if (percent > 100) | |
percent = 100; | |
if (percent < 0) | |
percent = 0; | |
progressBar1.Value = percent; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment