Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are querying the database on every keypress - this is going to cause you some lag when typing fast (or even normally)</p> <p>You would be better off throttling the request, we use this to throttle on the dispatcher thread.</p> <pre><code>public static class DispatcherExtensions { private static Dictionary&lt;string, DispatcherTimer&gt; timers = new Dictionary&lt;string, DispatcherTimer&gt;(); private static readonly object syncRoot = new object(); public static string DelayInvoke(this Dispatcher dispatcher, string namedInvocation, Action action, TimeSpan delay, DispatcherPriority priority = DispatcherPriority.Normal) { lock (syncRoot) { if (String.IsNullOrEmpty(namedInvocation)) { namedInvocation = Guid.NewGuid().ToString(); } else { RemoveTimer(namedInvocation); } var timer = new DispatcherTimer(delay, priority, (s, e) =&gt; { RemoveTimer(namedInvocation); action(); }, dispatcher); timer.Start(); timers.Add(namedInvocation, timer); return namedInvocation; } } public static void CancelNamedInvocation(this Dispatcher dispatcher, string namedInvocation) { lock (syncRoot) { RemoveTimer(namedInvocation); } } private static void RemoveTimer(string namedInvocation) { if (!timers.ContainsKey(namedInvocation)) return; timers[namedInvocation].Stop(); timers.Remove(namedInvocation); } } </code></pre> <p>Assuming you are not using MVVM, you could easily use this like so in your button click</p> <pre><code>Dispatcher.CurrentDispatcher.DelayInvoke("UpdateSearch", YourMethodThatStartsBackgroundThread,Timespan.FromSeconds(1)); </code></pre> <p>Also worth a note : f you are using 4.5 there is the <a href="http://www.jonathanantoine.com/2011/09/21/wpf-4-5-part-4-the-new-bindings-delay-property/" rel="noreferrer">Delay</a> property on bindings you could look at.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload