How to STOP Device.StartTimer mid flow

SwanneSwanne Member ✭✭

Hi all,

I have a number of buttons on my UI. Each button is intended to have 2 functions - a short press function and a long press function. When the user simply selects the button method_one is called. I want to implement the ability for the user to be able to press and hold the button for 5 seconds and call method_two.

I have been trying to use button.released to call method_one and use button.pressed to call Device.StartTimer for 5 seconds and method_two - which works but I cant figure out how to stop the timer called by onPress once the button is released and vice versa. I always receive both the button.pressed return and button.released return.

Please help :(

This is a snippet of what I have so far. The button.pressed is called from the XAML file

[code]`

public void OnAdminButtonPressed(object sender, EventArgs e)
{

            Device.StartTimer(TimeSpan.FromMilliseconds(5000.0), () =>
            {
                DisplayAlert("pressed", "5 seconds", "ok");
                return false;

            });         

    }


    public void OnAdminButtonReleased(object sender, EventArgs e)
    {

            Device.StartTimer(TimeSpan.FromMilliseconds(500.0), () =>
            {
                DisplayAlert("Released", "Immmediately Hopefully", "ok");
                return false;

            });          

    }

`
[/code]

Sign In or Register to comment.