Questions tagged as 'task'

1
answer

Difference between Task and Thread

I need to create a C # executable and I have the doubts: Do with thread or do with task ? In practice is there any difference between using Task and the "traditional" multi-thread ?? Is it true that a task...
asked by 13.04.2016 / 18:57
3
answers

When does not return Task in async methods?

Usually, in some time-consuming tasks, I use asynchronous methods: public async Task myLongRunningOperation(int i) { ... } However, in what situations do I not necessarily need to return a Task ? public async void myLongRunningOpera...
asked by 11.07.2017 / 04:02
2
answers

Modifying an item from a list shared by multiple threads

I have the following pseudo-code: public void Associar(List<Data> dados) { List<Task> tasks = new List<Task>(); foreach(dado in dados) { tasks.Add(AdicionarAsync(dado)); } Task.WaitAll(tasks.ToArray());...
asked by 22.06.2016 / 22:04
1
answer

What are the pros and cons of the TaskListObject implementation on ListObject

What are the advantages between the two implementations below. Both return a list with several products (more than 1k): public Task<List<Product>> GetAllProductsAsync() { var query = Products.ToList(); return Task.FromResu...
asked by 01.08.2015 / 16:26
1
answer

Task.Run always starts a new Thread?

When executing a list of tasks started through Task.Run, is it guaranteed that each one is executed on a different Thread? When reading the documentation, it seems to me that this is the default behavior, while doing the tests I was validatin...
asked by 10.08.2016 / 21:43
1
answer

Difference between Thread.Sleep and Task.Delay

I'm developing client / server communication, and using Task for asynchronous communication. Previously, I had already made another communication where I used Thread , works without problems and consumes little processing. In...
asked by 07.12.2017 / 20:08
1
answer

Task is not called

Personal I have an api where its processing takes around 6 hours of execution, so I added a Task.Factory.StartNew with the main processing. So when someone calls, it responds to StatusCode 200 and continues "heavy" processing with the Task: pu...
asked by 27.11.2017 / 19:36
1
answer

Sending birthday emails based on MySQL query

I have to create a function on the server of my site that sends a birthday email, containing an HTML code, to birthday emails. Detail: These birthdays are registered in a MySQL table that contains name, email, and date of birth. So if there a...
asked by 20.10.2015 / 17:51
1
answer

Why can not I capture exceptions triggered by async void?

Why can not I catch exceptions triggered by asynchronous methods that do not return Task ? public async void calcularPrecos() { var tabelaPreco = await getTabelaPreco(); /* Blá, blá, blá... */ } public void iniciarCalculos() {...
asked by 25.08.2016 / 04:12
1
answer

What is the difference between Task and async Task?

In the code below I wrote two methods, one with Task return and another async Task . What happens differently in the execution of these methods since for one I added in the construction the reserved word await and in the othe...
asked by 09.08.2018 / 16:53