You may need to limit the number of events that are handled. Do your requirements allow you to use the TextBox
Validated
or LostFocus
events instead?
If not you could look into Rx and throttle your TextChanged
event. This can be achieved like so:
IObservable<EventPattern<EventArgs>> observable = Observable.FromEventPattern(
txtText, "TextChanged").Throttle(TimeSpan.FromMilliseconds(500))
.Subscribe(ep=> DataGridView1[2, pos].Value = txtText.Text;);
You could also throttle with a Timer
.
Timer myTimer = new Timer();
myTimer.Interval = 500;
myTimer.Tick = OnTimerTick;
private void OnTimerTick(object o, EventArgs e)
{
myTimer.Stop();
DataGridView1[2, pos].Value = txtText.Text;
}
private void txtText_TextChanged(object sender, EventArgs e)
{
if(!myTimer.Enabled) myTimer.Start();
}