What I have is a string property for a username, connected to a text entry through MVVM, that whenever it is set, I call a method that checks the server to see if the username is available. Now I don't want this being called on every single time a key is typed, what I want instead is for it to detect when the user has stopped typing.
Currently this is my code...
private string _username;
public string Username
{
get => _username;
set
{
SetProperty(ref _username, value);
Task.Run(async () => await CheckUsernameExists(1000));
}
}
Then the CheckUsernameExists() method...
/// <summary>
/// Checks if the username already exists
/// </summary>
/// <returns></returns>
public async Task CheckUsernameExists(int timeoutInMilliseconds)
{
await Task.Delay(timeoutInMilliseconds);
try
{...
However this does not retrigger it, it just delays the call by 1 second.
I got the idea for a retriggerable delay from Unreal Engine 4 https://docs.unrealengine.com/en-US/BlueprintAPI/Utilities/FlowControl/RetriggerableDelay/index.html
What happens with the UE4 one is, the function is called once. Then it starts the timer on the retriggerable delay. If the function is called again while that timer is running, it restarts the timer. Then, only when it finishes, does it call the code after it.
Does anyone know how to do this in C#? Thanks!