I have a method to generate software activation key from User Information:
private async void GenerateAsync()
{
await Task.Run(() =>
You should use the more modern IProgress<T>
/Progress<T>
types:
var progress = new Progress<int>(value => { progressBar.Value = value; });
await Task.Run(() => GenerateAsync(progress));
void GenerateAsync(IProgress<int> progress)
{
...
progress?.Report(13);
...
}
This is better than Invoke
because it doesn't tie your business logic (GenerateAsync
) to a particular UI, or to any UI at all.
I use this method in Winforms:
progressBar1.Invoke((Action)(() => progressBar1.Value=50))