From IT Skills
Jump to: navigation, search


TAP,TAP method

TAP uses a single method to represent the initiation and completion of an asynchronous operation. This contrasts with both the Asynchronous Programming Model (APM or IAsyncResult) pattern and the Event-based Asynchronous Pattern (EAP). APM requires Begin and End methods. EAP requires a method that has the Async suffix and also requires one or more events, event handler delegate types, and EventArg-derived types... adding a TAP method to a class that already contains an EAP method name... If a method starts an asynchronous operation but does not return an awaitable type, its name should start with Begin, Start... consider adding a CancellationToken parameter


yield in C# works in analogy like yield of Generator in JS


await keyword causes the compiler to split the method into two parts. The first part ends with the operation that's started asynchronously. The second part is put into a callback method that's called when the operation completes... when writing asynchronous code that uses EF Core: Only statements that cause queries or commands to be sent to the database are executed asynchronously. That includes ToListAsync, SingleOrDefaultAsync, FirstOrDefaultAsync, and SaveChangesAsync. It doesn't include statements that just change an IQueryable, such as var students = context.Students.Where(s => s.LastName == "Davolio"). An EF Core context isn't thread safe: don't try to do multiple operations in parallel.

can't use the await operator in the body of a synchronous function, inside the block of a lock statement, and in an unsafe context... if throws an exception, await rethrows the exception.