Skip to content

Instantly share code, notes, and snippets.

@changhuixu
Created September 5, 2019 19:49
Show Gist options
  • Save changhuixu/72fb1646855a086671dcaad8b7bcd0bd to your computer and use it in GitHub Desktop.
Save changhuixu/72fb1646855a086671dcaad8b7bcd0bd to your computer and use it in GitHub Desktop.
var threads = new Thread[2];
threads[0] = new Thread(async () =>
{
using (var dbContext = new MyDbContext())
{
var account = await dbContext.BankAccounts.FindAsync(1);
account.Credit(100);
await dbContext.SaveChangesAsync();
}
});
threads[1] = new Thread(async () =>
{
using (var dbContext = new MyDbContext())
{
var account = await dbContext.BankAccounts.FindAsync(1);
account.Debit(200);
await dbContext.SaveChangesAsync();
}
});
foreach (var t in threads)
{
t.Start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment