c#-5.0

How is resumption from await implemented?

血红的双手。 提交于 2021-02-16 16:23:48
问题 I've been reading Eric Lippert's blog posts on Asynchrony in C# 5 (part 4 being particular relevant) and have watched Anders PDC10 talk on the subject and I'm unclear on how continuations from asynchronous methods are resumed in a single threaded context. Both sources discuss using asynchronous methods in a single threaded UI loop to improve responsiveness and in Anders' example he mentions that when an asynchronous task completes it's continuation is scheduled by the addition of a message to

.net 5.0 EF migrations adding stored proc models to ModelSnapshot

℡╲_俬逩灬. 提交于 2021-01-07 02:41:09
问题 I recently upgraded to .net 5.0 and I use entity framework. I edited a database model by adding an extra field and ran my normal script in powershell dotnet ef migrations add mig_name Since the C# upgrade though the upgrade script is trying to add all my Keyless models that I use for Stored Procs to the ModelSnapshot file. And what that means is that it tries to then drop these tables from the database even though they don't exist. protected override void Up(MigrationBuilder migrationBuilder)

.net 5.0 EF migrations adding stored proc models to ModelSnapshot

久未见 提交于 2021-01-07 02:40:53
问题 I recently upgraded to .net 5.0 and I use entity framework. I edited a database model by adding an extra field and ran my normal script in powershell dotnet ef migrations add mig_name Since the C# upgrade though the upgrade script is trying to add all my Keyless models that I use for Stored Procs to the ModelSnapshot file. And what that means is that it tries to then drop these tables from the database even though they don't exist. protected override void Up(MigrationBuilder migrationBuilder)

TaskCompletionSource : When to use SetResult() versus TrySetResult(), etc

假装没事ソ 提交于 2020-12-29 01:47:43
问题 I'm trying to wrap my head around the TPL, the new async / await features in C# 5, and the mysteries of TaskCompletionSource . One thing that isn't clear to me is when to use SetResult , SetException , and SetCancel versus TrySetResult , TrySetException and TrySetCancel . This is what MSDN has to say: This operation will return false if the Task is already in one of the three final states: RanToCompletion, Faulted, or Canceled. This method also returns false if the underlying Task has already

TaskCompletionSource : When to use SetResult() versus TrySetResult(), etc

北城余情 提交于 2020-12-29 01:42:40
问题 I'm trying to wrap my head around the TPL, the new async / await features in C# 5, and the mysteries of TaskCompletionSource . One thing that isn't clear to me is when to use SetResult , SetException , and SetCancel versus TrySetResult , TrySetException and TrySetCancel . This is what MSDN has to say: This operation will return false if the Task is already in one of the three final states: RanToCompletion, Faulted, or Canceled. This method also returns false if the underlying Task has already

Update progress bar in another form while task is running

核能气质少年 提交于 2020-06-01 07:40:09
问题 **Ultimately I am going to have four tasks running concurrently and have another form that contains four progress bars. I would like for each progress bar to update as it's work task is completing. Here's what I'm trying to do for starters. I have a form that has some buttons on it. When I click one I'm creating a new task to do some work. public partial class MyMainForm : Form { private void btn_doWork_Click(object sender, EventArgs e) { Task task = new Task(RunComparisons); task.Start(); }

Many awaits for Async method, or a single await for a wrapping Task.Run?

China☆狼群 提交于 2020-01-23 03:03:05
问题 Suppose we have to write down on database a list of 1000 elements, through an async flow. Is it better to await 1000 times an asynchronous insert statement, or to wrap all the 1000 inserts in one single synchronous method encapsulated into a Task.Run statement, awaiting one single time? For example, SqlCommand has every method coupled with his async version. In this case, we have an insert statement, so we can call ExecuteNonQuery or ExecuteNonQueryAsync . Often, on async/await guidelines, we

Significance of declaring a WPF event handler as 'async' in C# 5

Deadly 提交于 2020-01-22 13:17:44
问题 Imagine a WPF code-behind event handler: <Button Click="OnButtonClick" /> In C# 4 you would declare your handler as: private void OnButtonClick(object sender, RoutedEventArgs e) { ... } In C# 5 you can declare an async handler private async void OnButtonClick(object sender, RoutedEventArgs e) { ... } So what is WPF doing with this? A few minutes of searching about didn't turn anything up. It seems that it's possible to perform UI updates after await statements. Does this imply that the task