async Device.StartTimer

how to make Device.StartTimer async
like
Device.StartTimer(TimeSpan.FromMilliseconds(10), async () =>
{
await ButtonGetGPS_Clicked();
}

Best Answer

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    @Dannykhreet said:
    how to make Device.StartTimer async
    like
    Device.StartTimer(TimeSpan.FromMilliseconds(10), async () =>
    {
    await ButtonGetGPS_Clicked();
    }

    Remember that the block inside the {...} needs to return true or false

  • DannykhreetDannykhreet USMember ✭✭
    edited February 15

    @JohnHardman yes i return true and fals .
    all the code below` private async void btnStart_Clicked()
    {
    await ButtonGetGPS_Clicked();

            haveChanges = false;
            if (!stopwatch.IsRunning)
            {
                stopwatch.Start();
                Device.StartTimer(TimeSpan.FromMilliseconds(10), () =>
                {
    
                    lblStopwatch.Text = stopwatch.Elapsed.ToString();
                    totalSecond = TimeSpan.FromSeconds(20);
                    if (stopwatch.Elapsed <= totalSecond)
                    {
                        loc.ObtainMyLocation();
                        double latt = loc.GetLatPassive();
                        double lon = loc.GetLongPassive();
                        bool AltitudeChanged = savedPosition.Latitude != loc.GetLatPassive();
                        bool LongChanged = savedPosition.Longitude != loc.GetLongPassive();
                        haveChanges = AltitudeChanged || LongChanged;
    
                        if (haveChanges)
                        {
                            lblStopwatch.Text = stopwatch.Elapsed.ToString(); //"الوقت المنقضي  " + string.Format("{0:mm\\:ss}", timer.CurrentTime);
                            haveChanges = false;
                            stopwatch.Stop();
                            stopwatch.Reset();
                            TotalChanges += 1;
                            NumderTotalChanges.Text = TotalChanges.ToString();
                            // CurrentPositionOnTimer = NewPositionOnTimer;
                            savedPosition.Latitude = loc.GetLatPassive();
                            savedPosition.Longitude = loc.GetLongPassive();
                            stopwatch.Start();
                        }
                        else
                        {
                            TotalTime = stopwatch.Elapsed;
                            lblStopwatch.Text = stopwatch.Elapsed.ToString(); //"الوقت المنقضي  " + string.Format("{0:mm\\:ss}", timer.CurrentTime);
                        }
    
                    }
                    else
                    {
                        TotalLoops += 1;
                        NumderTotalLoops.Text = TotalLoops.ToString();
                        totalgps.Text = totgpsnumber.ToString();
                        stopwatch.Stop();
                        stopwatch.Reset();
                        // i need to make await work here 
                        await ButtonGetGPS_Clicked();
                         stopwatch.Start();
    
               }
                    }
    
    
    
                    if (!stopwatch.IsRunning)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
    
    
                }
    
                );
            }
        }`
    
Sign In or Register to comment.