Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,919 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a set of code that I want to repeat continuously until I explicitly tell it to stop (basically an infinite loop). However, I also need to be able to detect events (such as clicking a button). How can I do this?
Threads/Tasks are not an area I am extremely experienced in, but I am guessing that it probably would be a thread/task. Controlling it would not necessarily be by a Button, it would more likely be by when a specific condition was met while repeating the code being repeated. In my specific case, I want to start the camera & a
PreviewView
, and the repeating code would use TensorFlow to detect whether an item was found. Once an item is found, I want to stop the camera &PreviewView
. So the trigger would not actually be an Event, it would simply be the value of a Boolean variable. I would, of course, also have a Button (for which I implement the Click Event) that sets the value of that variable so that the user can stop the repeating code. So events may not have been the correct title for my question, but they are one of the things I need to continue to detect while repeating the code.You are working on Android platform, and stop the loop when the Boolean value changes, right? Do you try
while
statement?I am using Xamarin.Android with C#, and I have tried using a while statement. However, because a while statement would end up in an infinite loop (therefore never leaving the method in which it exists), the Boolean value would never change and other events would never be triggered.
Sign in to comment