title: Making a predictive text algorithm go faster
body: <p>I am working on a windows phone dialler app and I have implemented prediction text in my app. When user taps on keypad, contacts that match input are generated. Prediction is too slow, it also blocks my main thread that's why I have implemented BackGroundWorker But still having problems with the performance
  My code is:</p>
  
  <pre><code>private void dialer_TextChanged(object sender, TextChangedEventArgs e)
      {
          MainPage.DialerText = dialer.Text;
          if(!bw1.IsBusy)
          bw1.RunWorkerAsync();
       }
   void bw1_DoWork(object sender, DoWorkEventArgs e)
      {
          try
          {
              var digitMap = new Dictionary&lt;int, string&gt;() {
      { 1, "" },
      { 2, "[abcABC]" },
      { 3, "[defDEF]" },
      { 4, "[ghiGHI]" },
      { 5, "[jklJKL]" },
      { 6, "[mnoMNO]" },
      { 7, "[pqrsPQRS]" },
      { 8, "[tuvTUV]" },
      { 9, "[wxyzWXYZ]" },
      { 0, "" },
  };
              var enteredDigits = DialerText;
              var charsAsInts = enteredDigits.ToCharArray().Select(x =&gt; int.Parse(x.ToString()));
              var regexBuilder = new StringBuilder();
  
              foreach (var val in charsAsInts)
              regexBuilder.Append(digitMap[val]);
              MainPage.pattern = regexBuilder.ToString();
  
              MainPage.pattern = ".*" + MainPage.pattern + ".*";
  
  
          }
          catch (Exception f)
          {
              //  MessageBox.Show(f.Message);
          }
  
      }
  void bw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          SearchListbox.ItemsSource = listobj.FindAll(x =&gt; x.PhoneNumbers.Any(a=&gt;a.Contains(MainPage.DialerText)) | Regex.IsMatch(x.FirstName, MainPage.pattern));
      }
  </code></pre>
  
  <p>BackGroundWorker also blocking my main thread, hence when I tap on the keypad there's a lag while input values are added to the TextBox. I want to add input to the TextTox without any lag, how to do it? Thank you.</p>