Exemple #1
0
        /// <summary>
        /// Thread to calculating distance between mother and nanny
        /// </summary>
        /// <param name="sour"></param>
        /// <param name="dest"></param>
        public void Distance_Thread(string sour, string dest)
        {
            int result = myBl.CalculateDistance(sour, dest);

            result = result / 1000;                                                                                           // convert to kilometers
            Action act = (() => { TheAnswer.Text += "  " + result.ToString() + " kilometers"; Calculate.IsEnabled = true; }); // So that we can change the text box in the main thread window

            Dispatcher.BeginInvoke(act);
        }
        /// <summary>
        /// Filter the nannies by their address.
        /// appropriate distance is 10 km .
        /// this thread also puts the data in the dataList of the nannies.
        /// </summary>
        /// <param name="myMother"></param>
        private void CheckDistanceOfNanny_Thread(Mother myMother, Nanny myNanny, string distance)
        {
            int dis          = myBl.CalculateDistance(myMother.Address, myNanny.Address);
            int MAX_DISTANCE = int.Parse(distance) * 1000; // in km

            if (dis < MAX_DISTANCE)
            {
                Action <Nanny, int> act = AddNannyToList;
                Dispatcher.BeginInvoke(act, myNanny, dis);
            }
        }