I have a c# entity framework application. I am trying to run a stored procedure from code (no problem with that). its long running, around 30 mins. I write a log of each transaction to a SQL table as the process goes through. I am looking to initiate the procedure from the app but then show the last 10 records of the log on screen maybe re querying every 10 seconds. this will show the progress.
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
Task.Run(() => _serviceProduct.RefreshAllAsync());
_cvsLog = (CollectionViewSource)(FindResource("cvsLog"));
var dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = TimeSpan.FromSeconds(10);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
_cvsLog.Source = _serviceProduct.GetRefreshLog();
}
I have altered the code to simplify. The thread blocks on the dispatcherTime_Tick process. It looks like the stored procedure is away fine.
Here is the called service.
public ObservableCollection<RefreshLog> GetRefreshLog()
{
using (var db = new HiggidyPiesEntities())
{
var recs = (from x in db.RefreshLogs orderby x.LG_ID descending select x).Take(30);
var obs = new ObservableCollection<RefreshLog>(recs);
return obs;
}
}
I have been down the background worker route and task.run but the procedure keeps blocking the thread.
I have even thought of initiating a SQL job from code and then monitor the log after that with calls to the database. Maybe service broker may be a choice to consider?
any thoughts of what road I should go down with this type of problem? thanks in advance Scott