locked
Cancelling Await function

    Question

  • I am working on a windows 8 project in which I am playing a song and changing images on certain duration of song using await functions.

    I also insert some buttons when i tap the button it should play the song from the time I have set it in with timespan.

    The Problem is when I click on the Time span the await functions still runs and it makes non-sense while running ProgramI.

    I have attached the code example here.. Please help to cancel await tasks when clicking  a button

     public sealed partial class suprabatham : Page
        {
            bool onea,twoa,threea,
            public suprabatham()
            {
                this.InitializeComponent();
    
    
                sa.Source = new Uri("ms-appx:///Assets/Audio/1.mp3");
                sa.Play();
    
               
    
                a();
    
     
            }
    
            //Function tap changing image
            async public void a()
        {
    
                onea = true;
                twoa= false;
                threea= false;
                
               
              
    
            BitmapImage bm = new BitmapImage(new Uri(@"ms-appx:///Assets/Suprabatham/1_1.png"));
            text.Source = bm;
    
            BitmapImage am = new BitmapImage(new Uri(@"ms-appx:///Assets/Hover/1.png"));
            one.Source = am;
    
            
            colour();
    
            b();
    
    
        }
    
       async public void b()
        {
            onea = false;
            twoa = true;
            threea = false;
            
           
            
    
             BitmapImage bm = new BitmapImage(new Uri(@"ms-appx:///Assets/Suprabatham/1_2.png"));
            text.Source = bm;
    
            BitmapImage am = new BitmapImage(new Uri(@"ms-appx:///Assets/Hover/2.png"));
            two.Source = am;
    
            await Task.Delay(19900);
    
            colour();
    
           c();
    
        }
    
    
      async  public void c()
        {
            onea = false;
            twoa = false;
            threea =true;
            
            BitmapImage bm = new BitmapImage(new Uri(@"ms-appx:///Assets/Suprabatham/1_3.png"));
            text.Source = bm;
    
            
            BitmapImage am = new BitmapImage(new Uri(@"ms-appx:///Assets/Hover/3.png"));
            three.Source = am;
    
            await Task.Delay(37000);
            colour();
    }
    
      public void colour()
       {
            if(onea)
            {
                BitmapImage cm = new BitmapImage(new Uri(@"ms-appx:///Assets/Normal/1.png"));
                one.Source = cm;
            }
    
            if (twoa)
            {
               
               BitmapImage cm = new BitmapImage(new Uri(@"ms-appx:///Assets/Normal/2.png"));
               two.Source = cm;
            }
    
            if(threea)
            {
                BitmapImage cm = new BitmapImage(new Uri(@"ms-appx:///Assets/Normal/3.png"));
                three.Source = cm;
            }
    
    }
    
    
      // on Key Tapping Functions 
        private void one_Tapped(object sender, TappedRoutedEventArgs e)
       {
         
            
            
            if (sa.CanSeek)
            {
                sa.Position = new TimeSpan(0, 0, 0, 0, 00000);
    
            }
            a();
        }
    
        private void two_Tapped(object sender, TappedRoutedEventArgs e)
        {
       
            if (sa.CanSeek)
            {
                sa.Position = new TimeSpan(0, 0, 0, 0, 29200);
    
               
    
            }
    
       
            b();
        }
    
       
    
        private void three_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (sa.CanSeek)
            {
                sa.Position = new TimeSpan(0, 0, 0, 0, 49100);
    
            }
            c();
        }
    
    
    Thanks for any Help

    N.P.SARAVANA KUMAR

    Thursday, March 13, 2014 11:47 AM

Answers