0

i have recently started working on C# and i am very amateur at it please any help in the problem decirbed below will b very helpful for me

What i wanted to do is have an access of video_panel in event handler as-well but right now i dont know how to do that i tried to declare media element global and set its value to video_panel but still no use what should i do what i want to is instead of displaying a message pause a video currently playing

namespace Play_pause
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

  static   int index = 0;
  static  System.Timers.Timer aTimer = new System.Timers.Timer();
    public MainWindow()
    {
        InitializeComponent();
       video_panel.Play();

        // Hook up the Elapsed event for the timer.
        aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

        // Set the Interval to 2 seconds (2000 milliseconds).
        aTimer.Interval = 2000;

        aTimer.Start();




    }

    private static void OnTimedEvent(object source, ElapsedEventArgs e)
    {



        index++;
        if (index %2==0)
        {
            MessageBox.Show("Can't access media element in the event handler/n how to    
            set it global?");




        }

    }    
}

}

ahmad05
  • 438
  • 2
  • 6
  • 23

1 Answers1

1

Read the answers here again, they show how to make a variable global.

But this wont solve your problem. Since your OnTimedEvent-method is static, you can access only static variables. I dont think your OnTimedEvent should be static, so try to remove the word "static" and now you can acess global variables (e.g. your video_panel).

Community
  • 1
  • 1
Florian Gl
  • 5,984
  • 2
  • 17
  • 30
  • yes the questions are pretty much the same ... i know this but i am using different technique here instead of using dispatcherTimer i am using System.Timers.Time – ahmad05 Oct 02 '12 at 13:24
  • well i just did that ..sorry for being informal..... but really need help in this case – ahmad05 Oct 02 '12 at 13:35