Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows DateTime time
I need help with making a code that checks every second if Datetime is started. If it is started it should close the already running function. I know dispatchertimer but I want it to run the thread in background. The reason is because I have a mediaplayer that plays till datetime is started, causing the movie to restart every 1 second.
 
I would be very thank full if you guys could help me, a little bit desperate...
 
        Dictionary<string, string> listBox3Dict = new Dictionary<string, string>();
        private bool listbox3job()
        {
            AxWMPLib.AxWindowsMediaPlayer axWmp =
wfh.Child as AxWMPLib.AxWindowsMediaPlayer;
            DateTime? start = DateTimePicker1.Value;
            DateTime? end = DateTimePicker2.Value; // This. End date. If end date. Stop movie.
            DateTime now = DateTime.Now;
 
            if (start == null || end == null)
            {
            }
            else if (now >= start.Value && now <= end.Value)
                {
                    foreach (var selected in listBox3.Items)
                    {
                        string s = selected.ToString();
 
                        if (listBox3Dict.ContainsKey(s))
                        {
                            axWmp.URL = (listBox3Dict[s]);
                        }
                    }
 
                return true;
            }
            return false;
        }
Posted 17-Apr-13 11:18am
klottim197
Comments
Sergey Alexandrovich Kryukov at 17-Apr-13 19:17pm
   
"I know dispatchertimer but I want it to run the thread in background."... how one prevents another?
What in the background, a movie?!
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Little code snippet about timer. Hope that help.
 
        Timer timer;
        int secondsToPlay;
        private void StartPlay_Click(object sender, EventArgs e)
        {
            timer = new Timer();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 1000;
            DateTime Start = dateTimePicker1.Value;
            DateTime End = dateTimePicker2.Value;
            TimeSpan total = End - Start;
            secondsToPlay = (int)total.TotalSeconds;
            // Start video etc ...
            timer.Start();
        }
 
        void timer_Tick(object sender, EventArgs e)
        {
            secondsToPlay--;
            if (secondsToPlay <= 0)
            {
                // Stop video etc ...
                timer.Stop();
            }
        }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100