0

I'm building a Visual Studio .NET application in c# with 2 databases and Entity Framework. At first, I thought it would be better to load the most used datas in static Lists when the app is launched, but it was a bit too long, so now I try to use Tasks. I have one method per table I want to load, and I call them in a more general method :

public static void fillConstantes()
    {
        new Task(FillFiches).Start();
        new Task(FillCustomers).Start();
        new Task(FillEmployees).Start();
        new Task(FillContact1).Start();
        new Task(FillServiceItems).Start();
        new Task(FillServiceLine).Start();
    }

The fact is, if if I try to access the datas in another class and the task isn't finished, it crashes, obvisouly. So, I was wondering if there's a good way to check if the tasks are done, are if I just have to check if it worked whenever I try to retrieve datas ?

Thanks for your help !

1 Answers1

0
  Task t = new Task(() => { });
  t.Start();

you can use t.IsCompleted for your purpose

Mukesh Methaniya
  • 752
  • 1
  • 5
  • 13