Watch application

I am creating a synchronization application in C # .Net. I have images for each digit from 0 to 9. I have a timer in the constructor of the main page that indicates every second

DispatcherTimer tmr = new DispatcherTimer();
tmr.Interval = TimeSpan.FromSeconds(1);
tmr.Tick += new EventHandler(tmr_Tick);
tmr.Start();

void tmr_Tick(object sender, EventArgs e)
    {
        dt = DateTime.Now;
        UpdateSecondsImages(dt);
    }


private void UpdateSecondsImages(DateTime dt)
    {
        secondSource2 = dt.Second % 10;
        secondDigit2.Source = digimgs[secondSource2];
        if (secondSource2 == 0)
        {
            secondSource1 = dt.Second / 10;
            secondDigit1.Source = digimgs[secondSource1];
        }

        if (secondSource1 == 0)
        {
            UpdateMinuteImages(dt);
        }
    }

But the problem that I am currently facing is that this code may skip a second for a minute. Please suggest an alternative way to make this smooth in terms of performance.

+3
source share
3 answers

Simple. , : ", 1 , ". . , API- . , , , DateTime.Now.

: , 1.02 . , 50 . , "49,98" ( "49" ), , "51.00".

1 . 500-750 . , . , , , .

:  tmr.Interval = TimeSpan.FromMilliSeconds(500);

+3

, , CompositionTarget.Render . UI . , :).

, (cos() sin() ). ( ), .

, .

+1

Yesterday, we launched a contest with Ball Watch USA to create watches in Silverlight. I recommend using the Storyboard to rotate the second hand 360 degrees for 1 minute and set the storyboard permanently. Here are some links:

0
source

Source: https://habr.com/ru/post/1748976/


All Articles