Created
April 23, 2017 06:11
-
-
Save caviles/6dd359c421e95e096e0c046bf5f05383 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
avoid .Result Or Wait on task as it will block threads and can lead to deadlocks | |
always wrap your calls in try catch as the async errors are generally swallowed by the framework | |
public async Task<Customer> Get(int id) | |
{ | |
// you are on a particular thread here | |
var customer = await SomeAsyncFunctionThatGetsCustomer(id).ConfigureAwait(false); // doesn't have find the orginal thread it used so is much faster | |
// now you are on a different thread! will that cause problems? | |
return customer; | |
} | |
https://www.codeproject.com/Articles/147248/Concurrent-Collections-with-NET
https://msdn.microsoft.com/en-us/library/dd997373(v=vs.110).aspx
These thread safe collections don't have to be locked
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Task.Run(() => DoWorkAsync()); //can be awaited will create a new thread
Use concurrent collections when working with threads and collections because - for instance instead of queue use concurrentqueue