Nie wiem czemu metody nie działają równocześnie a jedna po drugiej zamiast 3 sekund działają 9???
Chodzi o metodę Index? Ktoś wie co trzeba zmienić ???
public class DeptController : Controller
{
private MyDb db = new MyDb();
public async Task<string> GetCountryAsync()
{
await Task.Delay(3000); //Use - when you want a logical delay without blocking the current thread.
return "India";
}
public async Task<string> GetCountry1Async()
{
await Task.Delay(3000); //Use - when you want a logical delay without blocking the current thread.
return "India";
}
public async Task<string> GetCountry2Async()
{
await Task.Delay(3000); //Use - when you want a logical delay without blocking the current thread.
return "India";
}
public async Task<ActionResult> Index()
{
Stopwatch spot = new Stopwatch();
spot.Start();
string napis =await GetCountryAsync();
string napis1 = await GetCountry1Async();
string napis2 = await GetCountry2Async();
spot.Stop();
TimeSpan span = spot.Elapsed;
ViewBag.Stop = span;
return View(await db.Departments.ToListAsync());
}
public ActionResult Create()
{
return View(new Department());
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create(Department dept)
{
if(ModelState.IsValid)
{
db.Departments.Add(dept);
await db.SaveChangesAsync();
Thread.Sleep(2000);
Console.WriteLine("Wiadomość");
return RedirectToAction("Index");
}
else
{
return View(dept);
}
}
public async Task<ActionResult> Details(int id)
{
Department dept = await db.Departments.FindAsync(id);
return View(dept);
}
}
}