async , task , await mantığı ve kullanım örneği
async void , değer döndürmeyen fonksiyonlara güvenlik amacıyla tanımlanmaz. / 2014
async mantığı tehread pool'un şişmesini engellemek ve işlem süresini en uzun işlemin süresine kadar düşürmek için kullanılır.
[HttpPost("FileUpload")]
public async Task<IActionResult> FotoYukle(List<IFormFile> files)
{
long size = files.Sum(f => f.Length);
var filePaths = new List<string>();
foreach (var formFile in files)
{
if (formFile.Length > 0)
{
// full path to file in temp location
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img", formFile.FileName); //we are using Temp file name just for the example. Add your own file path.
filePaths.Add(filePath);
using (var stream = new FileStream(filePath, FileMode.Create))
{
await formFile.CopyToAsync(stream);
}
}
}
// process uploaded files
// Don't rely on or trust the FileName property without validation.
//return Ok(new { count = files.Count, size, filePaths });
return Ok(new { count = files.Count, size, filePaths });
}
2014 yılında çekilen async await task mantığını anlatan referans video
https://www.youtube.com/watch?v=palXWq8li-8