Я придумал это в своем определении класса.
Я хотел немедленно запустить свое действие, если в течение периода времени не было никаких действий (в примере 3 секунды).
Если что-то произошло за последние три секунды, я хочу отправить последнее, что произошло за это время.
private Task _debounceTask = Task.CompletedTask;
private volatile Action _debounceAction;
/// <summary>
/// Debounces anything passed through this
/// function to happen at most every three seconds
/// </summary>
/// <param name="act">An action to run</param>
private async void DebounceAction(Action act)
{
_debounceAction = act;
await _debounceTask;
if (_debounceAction == act)
{
_debounceTask = Task.Delay(3000);
act();
}
}
Итак, если я разделил свои часы на каждую четверть секунды
TIME: 1e&a2e&a3e&a4e&a5e&a6e&a7e&a8e&a9e&a0e&a
EVENT: A B C D E F
OBSERVED: A B E F
Обратите внимание, что не делается никаких попыток отменить задачу раньше, поэтому возможно, что действия будут накапливаться для За 3 секунды до того, как он станет доступен для сборки мусора.
Попробуйте что-то вроде этого:
public class CustomModelBinder : DefaultModelBinder {
protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) {
if(propertyDescriptor.Name == "Order") {
...
return;
}
if(propertyDescriptor.Name == "Item") {
...
return;
}
base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
}
}
переопределить BindProperty из DefaultModelBinder:
public class CustomModelBinder:DefaultModelBinder
{
protected override void BindProperty( ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor )
{
if (propertyDescriptor.PropertyType == typeof(Range))
{
base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
}
// bind the other properties here
}
}
Думаю, я бы зарегистрировал две разные пользовательские связующие модели, одну для Order и одну для Item, и позволил бы связующей модели по умолчанию обрабатывать Range и IssueForm.