Skip to content

Instantly share code, notes, and snippets.

@mrtank
Created April 7, 2020 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrtank/124ee282c33dcb32c734af4874772a14 to your computer and use it in GitHub Desktop.
Save mrtank/124ee282c33dcb32c734af4874772a14 to your computer and use it in GitHub Desktop.
public int counter { get; set; }
public async void test()
{
var uiThreadScheduler = TaskScheduler.FromCurrentSynchronizationContext();
while(true)
{
Task backgroundTask = Task.Run (async () => {
await Task.Delay(300);
Interlocked.Increment(ref this.counter);
});
backgroundTask.ContinueWith(() => { textBox.Text = counter.ToString(); }, uiThreadScheduler);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment