There is a console application that accepts incoming connections, reads a command, executes it, and returns a response (or executes without an answer). The scope of the application is as follows:
1) Http requests.
2) Database requests.
3) Sending commands by socket to another console application.
I rummaged through many articles on the Internet, where it is written that using ConfigureAwait (false) is unacceptable in a GUI application, since it requires the original context after the asynchronous function. I have a console application in which, as I understand it, it does not matter in what context the function will continue to be performed. Do I think correctly? Can the ubiquitous use of ConfigureAwait (false) in my application turn sideways? And more specifically:
1) Is deadlock possible?
2) Increased system load / reduced performance.
3) Execution of asynchronous functions not in a predetermined order (I read it in one article).
4) Or any other problem about which I do not know.
Sample code from the program:
private async Task UpdateUserBalance(int id, decimal amount) { Transaction transaction = await DataBase.StartTransactionAsync().ConfigureAwait(false); try { UserModel user = await UserModel.FindAsync(id, transaction).ConfigureAwait(false); user.balance += amount; await user.Update(transaction).ConfigureAwait(false); await transaction.CommitAsync().ConfigureAwait(false); } catch (Exception e) { await transaction.RollbackAsync().ConfigureAwait(false); } finally { transaction.Dispose(); } } There are also async void functions that cause mistrust towards deadlocks. Example:
class TimerClass { private Timer _timer; // using System.Timers; public TimerClass() { _timer = new Timer(5 * 1000); _timer.Elapsed += Callback; _timer.AutoReset = true; _timer.Enabled = true; _timer.Start(); } private async void Callback(object state, ElapsedEventArgs e) { // code await SomeAsyncFunc().ConfigureAwait(false); // code } } And one more question. Is deadlock possible in this code? Because it is used task. Result.
List<Task> tasks = new List<Task>(); for(int i = 0; i < someLength; i++) { tasks.Add(SomeTaskFunc()); } await Task.WhenAll(tasks); for(int i = 0; i < tasks.Count; i++) { Task task = tasks[i]; // Дальше идут операции с task.Result }