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);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)