I have a problem. I'm in a WPF application and I want to do a SQL query in the background, all this I already have, the problem that at the time of making the "query", the UI is branded and I do not know why, if I'm doing it in another thread .
This code here works, but the UI calls me. On the other hand, if we erase the FOR and put a Thread.Sleep (5000), it works perfectly. I'm using NET4.0
private void Buscar()
{
ShowMessage = "Buscando...";
IsBusy = true;
ShowProgressRing = true;
Task.Factory.StartNew(() =>
{
//Thread.Sleep(5000); // Simulate SQL query
Articulos = new ObservableCollection<Articulo>();
for (var i = 0; i < 500; i++)
{
Articulos.Add(new Articulo
{
Codigo = i.ToString(),
NombreDelArticulo = "PRODUCT NAME",
PrecioFinal = 1m
});
}
IsBusy = false;
}).ContinueWith(x =>
{
}, TaskScheduler.FromCurrentSynchronizationContext());
}