public int AddStudent(Student s) { //Insert the student and update the index arr_student.Insert(student_index++,s); return 0; }
private void AddToCollection(Student student) { // This line of code is intended to simulate network or database latency // It causes a non-responsive UI // Do not remove this line of code as a way of completing the assignment // You MUST use a C# task to get credit Thread.Sleep(5000); students.Add(student); int count = students.Count; MessageBox.Show("Student created successfully. Collection contains " + count.ToString() + " Student(s)."); }
private void btnCreateStudent_Click(object sender, RoutedEventArgs e) { Student newStudent = new Student(); newStudent.FirstName = txtFirstName.Text; newStudent.LastName = txtLastName.Text; newStudent.City = txtCity.Text; ClearForm(); Task task1 = new Task(() => AddToCollection(newStudent)); task1.Start(); }
private void btnCreateStudent_Click(object sender, RoutedEventArgs e) { Student newStudent = new Student(); newStudent.FirstName = txtFirstName.Text; newStudent.LastName = txtLastName.Text; newStudent.City = txtCity.Text; ClearForm(); //use asynchronous task to add student Task.Run(() => AddToCollection(newStudent)); }
private void btnCreateStudent_Click(object sender, RoutedEventArgs e) { Student newStudent = new Student(); newStudent.FirstName = txtFirstName.Text; newStudent.LastName = txtLastName.Text; newStudent.City = txtCity.Text; // Use a lambda expression to pass the student object in the collection keepin UI responsive Task task1 =new Task(() =>AddToCollection(newStudent)); task1.Start(); ClearForm(); }
private void btnCreateStudent_Click(object sender, RoutedEventArgs e) { Student newStudent = new Student(); newStudent.FirstName = txtFirstName.Text; newStudent.LastName = txtLastName.Text; newStudent.City = txtCity.Text; // multithreading object Task adds a new Task object that takes no action(sleep is already taken care of //and creates the option to add a new student using the method AddToCollection Task addTask = new Task(() => AddToCollection(newStudent)); ClearForm(); AddToCollection(newStudent); }
private void AddToCollection(Student student) { // This line of code is intended to simulate network or database latency // It causes a non-responsive UI // Do not remove this line of code as a way of completing the assignment // You MUST use a C# task to get credit Thread.Sleep(5000); students.Add(student); int count = students.Count; MessageBox.Show("Student created successfully. Collection contains " + count.ToString() + " Student(s)."); student_index++; //Use delegate to get the object which in other thread Action methodDelegate = delegate() { TestBtnIsEnabled(); }; this.Dispatcher.BeginInvoke(methodDelegate); }