Beispiel #1
0
 public void mother()
 {
     while (true)
     {
         lock (lockObj)
         {
             if (plate == plateState.empty)
             {
                 //image.Source = new BitmapImage(new Uri(@"image/orange.jpg", UriKind.RelativeOrAbsolute));
                 //label.Content = "母亲:我在盘子里放了桔子。";
                 this.image.Dispatcher.Invoke(new Action(() =>
                 {
                     image.Source = new BitmapImage(new Uri(@"image/orange.jpg", UriKind.RelativeOrAbsolute));
                 }
                                                         ));
                 this.label.Dispatcher.Invoke(new Action(() =>
                 {
                     label.Content = "母亲:我在盘子里放了桔子。";
                 }));
                 System.Threading.Thread.Sleep(1000);
                 plate = plateState.orange;
             }
         }
     }
 }
Beispiel #2
0
 public void daughter()
 {
     while (true)
     {
         lock (lockObj)
         {
             if (plate == plateState.orange)
             {
                 //image.Source = new BitmapImage(new Uri(@"image/orange.jpg", UriKind.RelativeOrAbsolute));
                 //label.Content = "女儿:我不吃桔子。";
                 this.image.Dispatcher.Invoke(new Action(() =>
                 {
                     image.Source = new BitmapImage(new Uri(@"image/orange.jpg", UriKind.RelativeOrAbsolute));
                 }
                                                         ));
                 this.label.Dispatcher.Invoke(new Action(() =>
                 {
                     label.Content = "女儿:我不吃桔子。";
                 }));
                 System.Threading.Thread.Sleep(500);
             }
             else if (plate == plateState.apple)
             {
                 //image.Source = new BitmapImage(new Uri(@"image/apple.jpg", UriKind.RelativeOrAbsolute));
                 //label.Content = "女儿:我吃了苹果。";
                 this.image.Dispatcher.Invoke(new Action(() =>
                 {
                     image.Source = new BitmapImage(new Uri(@"image/apple.jpg", UriKind.RelativeOrAbsolute));
                 }
                                                         ));
                 this.label.Dispatcher.Invoke(new Action(() =>
                 {
                     label.Content = "女儿:我吃了苹果。";
                 }));
                 System.Threading.Thread.Sleep(1000);
                 plate = plateState.empty;
             }
             else if (plate == plateState.empty)
             {
                 //image.Source = new BitmapImage(new Uri(@"image/plate.jpg", UriKind.RelativeOrAbsolute));
                 //label.Content = "空盘子,请等待。。。。";
                 this.image.Dispatcher.Invoke(new Action(() =>
                 {
                     image.Source = new BitmapImage(new Uri(@"image/plate.jpg", UriKind.RelativeOrAbsolute));
                 }
                                                         ));
                 this.label.Dispatcher.Invoke(new Action(() =>
                 {
                     label.Content = "空盘子,请等待。。。。";
                 }));
                 System.Threading.Thread.Sleep(500);
             }
         }
     }
 }