internal void delayTimer_Tick(object sender, EventArgs e)
{
delayTimer.Stop();
if (Autocompleting == null)
throw new NullReferenceException("SeachMethod cannot be null.");
string text = txtBox.Text;
source = new CancellationTokenSource();
var context = Statics.ExportThreadContext();
var task = Task.Factory.StartNew<IEnumerable>(() =>
{
Statics.ImportThreadContext(context);
return Autocompleting(text, source.Token);
}, source.Token);
task.ContinueWith(res =>
{
if (res.IsFaulted)
Async.OnAsyncUnhandledException(res.Exception.InnerExceptions.FirstEx(), Window.GetWindow(this));
else
{
lstBox.ItemsSource = res.Result;
if (lstBox.Items.Count > 0)
{
lstBox.SelectedIndex = -1;
pop.Width = lstBox.Width;
pop.Height = lstBox.Height;
pop.IsOpen = true;
}
else
{
pop.IsOpen = false;
}
}
}, source.Token, TaskContinuationOptions.NotOnCanceled, TaskScheduler.FromCurrentSynchronizationContext());
}