Skip to content

Instantly share code, notes, and snippets.

@iyevhen
Last active August 29, 2015 14:26
Show Gist options
  • Save iyevhen/5186dd6623b6538ebe43 to your computer and use it in GitHub Desktop.
Save iyevhen/5186dd6623b6538ebe43 to your computer and use it in GitHub Desktop.
Progress which doesn't throw exceptions for invalid input parameters
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