Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys

I am not sure what i misses here been doing this for days. Hope someone can help me out.

What I want is that I have a progress loading while constructing the data and binding it.

I am doing this inside UserControl_Loaded.

Other Notes:
-this loading adorner is taken from this
WPF Loading Wait Adorner[^]

((MainWindow)dp).LoadingAdorner.IsAdornerVisible = true;

C#
   DependencyObject dp = this._owner;
  //shows the loading but freezes and loading not moving
  //from here

  ((MainWindow)dp).LoadingAdorner.IsAdornerVisible = true;
  //to here

  Person person = new Person();
  List<Address> addresses= new List<Address>();
  List<Contact> contacts = new List<Contact>();
  Employee emp = new Employee();
  List<Role> roles= new List<Role>();
  List<string> nationalities = new List<string>();

  List<Task> tasks = new List<Task>();

  Task taskPerson = Task.Factory.StartNew(() =>
  {
      this.Dispatcher.BeginInvoke(new Action(() =>
      {
          var personSvcAgent = new ServiceAgent.PersonSvcAgent();
          person = personSvcAgent.GetPersonById(_employeeModel.OwnerID);

      }), null);
  });
  tasks.Add(taskPerson);

  Task taskContact = Task.Factory.StartNew(() =>
  {
      this.Dispatcher.BeginInvoke(new Action(() =>
      {
          var contactSvcAgent = new ServiceAgent.ContactSvcAgent();
         contacts = contactSvcAgent.GetContactByOwnerId(person.Id);
      }), null);
  });
  tasks.Add(taskContact);

  Task taskAddress = Task.Factory.StartNew(() =>
  {
      this.Dispatcher.BeginInvoke(new Action(() =>
      {
          var addressSvcAgent = new ServiceAgent.AddressSvcAgent();
          addresses = addressSvcAgent.GetAddressByOwnerId(person.Id);
      }), null);
  });
  tasks.Add(taskAddress);


Task taskEmployee = Task.Factory.StartNew(() =>
  {
      this.Dispatcher.BeginInvoke(new Action(() =>
      {
          var employeeSvcAgent = new ServiceAgent.EmployeeSvcAgent();
          emp = employeeSvcAgent.GetEmployeeById(_employeeModel.EmployeeId);
      }), null);
  });
  tasks.Add(taskEmployee);

 Task taskRoles = Task.Factory.StartNew(() =>
  {
      this.Dispatcher.BeginInvoke(new Action(() =>
      {
          roles = new RoleSvcAgent().GetAllRole();
          nationalities = Nationalities.GetAllNationalities();
      }), null);
  });
  tasks.Add(taskRoles);

  var ui = TaskScheduler.FromCurrentSynchronizationContext();
  Task.Factory.ContinueWhenAll(tasks.ToArray(),result =>
  {
      //when i put the code here it will load all the person info before it shows the loading
      //from here
      ((MainWindow)dp).LoadingAdorner.IsAdornerVisible = true;
      //to here

      LoadPersonInfo( person);

  }, CancellationToken.None, TaskContinuationOptions.None, ui);
Posted
Updated 9-Jul-13 18:44pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900