I have a helper extension method that I use for path string validation. It looks as below. It's purpose is to work with network paths as well, so in case a network resource is not available, I do not want my applications to freeze, hence the specified timeout etc.public static bool IsExistingFilePath(this string source, int numberOfAttempts = 3, int timeout = 300){    for (int i = 0; i < numberOfAttempts; i++)    {        var task = new Task<bool>(() => File.Exists(source));        task.Start();        bool exists = task.Wait(timeout) && task.Result;        if (exists)        {            return true;        }        else            continue;    }    return false;}I also have a generic text box control, where I want to validate the provided path - and indicate if path is not correct. I want this auto text box validation to happen as infrequently as possible, because I don't want to run this loop of File.Exists() tasks when the path is being provided at the moment (e.g. user typing) etc.My current approach is that I have a property that is bound to textbox text, and whenever it is updated, the validation is performed (update source trigger = property changed, mode = two way).However, there is a problem, because property setter is not accessed when I paste into the text box nor when I write in it. I had set up a bunch of event handlers (OnPaste and LostFocus), but it's becoming unmanageable and appears not correct - and also appears to fire more times then necessary.Then I thought about data validation from XAML with a ValidationRule class, but that actually works more or less like with KeyUp.What would be the correct way to perform validation only when needed?When text is pasted into boxWhen property is changed for whatever reasonWhen textbox is clearedWhen text is changed (for instance, a proper path is pasted and a user decides to change it manually, e.g. use different drive)
Path validation helper in a 'path input box'
c#;io;wpf