“I’m currently working on a .NET MAUI project. Let’s say a user can start and stop recording using the same button. I’d like to have a continuous animation while recording, and when the button is stopped, the animation should stop as well. This functionality works, but when I click the button multiple times quickly in succession, the app crashes and stops functioning. Any advice on how to address this issue would be greatly appreciated?
private bool isRecording = false;
public MainPage()
{
InitializeComponent();
BindingContext = new MainViewModel();
}
public void StartStopButton_Clicked(object sender, EventArgs e)
{
isRecording = !isRecording;
if (isRecording)
{
AnimateButton(testButton);
}
else
{
...
}
private async Task AnimateButton(View view)
{
while (isRecording)
{
await view.ScaleTo(2, 200, Easing.SinInOut);
await view.ScaleTo(1, 200, Easing.SinInOut);
}
}