-1

I'm new to ASP.NET Core, so maybe I'm doing something wrong, here is my issue:

What do I need: After loading start page start loading application specific data from Azure Storage in background and show it's status on front-end

What I did to achieve this:

public ViewResult Index()
{
    var homeModel = new HomeModel();
    Task.Run(() =>
    {
        // Some specific work to do...
        System.Threading.Thread.Sleep(4000);
    });

    return View(homeModel);
}

When I run this code front-end view doesn't displayed until Task is not finished, even though it's different managed thread (also I tried to do the same with new Thread.Start(() => ...); ).

My question is: What it the reason of such behavior? As I said I'm new to ASP.NET Core and I've not worked with ASP.NET of previous versions.

I have some ideas how to work around with this behavior but I want to know the right way to do it and understand the reason :)

P.S. I'm using SignalR for updating views from back-end.

2 Answers2

0

Your approach to application startup jobs is wrong. Have a look at the IApplicationLifetime interface. Here is a question about it

Tewr
  • 3,713
  • 1
  • 29
  • 43
-2
ThreadStart starter = delegate { SomeVoid(somevar); };
  Thread tr = new Thread(starter);
  tr.IsBackground = true;
  tr.Start();
  tr.Join();

if need more thread use with list of thread and loop, sorry if i don't help you