To have an un-frozen app when executing long-running query you need to execute it on separate thread. Try using BackgroundWorker
. It has ReportProgress
that you can use. there are 2 scenarios:
1 - you have a single query which modifies some table in batch, but it runs long time on DB server. In this case you can, (and there are mult scenarios here too) if possible, write batch log into some table. You can create temp trigger and temp table query target table. Trigger will update temp table when record processed. In your background worker write a SQL query to query the temp table and see how many rows are logged. Do it until job marked as "DONE" (in same temp table)
2 - in this scenario it is easy to track progress because here you do all SQL one row at the time in your code. So you know how many updates you have and can precisely tell, for example "processing 5 of 1000". In your background worker you will do this job in DoWork
and on every DB call you will call ReportProgress
.
How to implement BackgroundWorker
you can find 1000 examples online. For the scenario #2 this is pretty much it. For the scenario #1, it depends what you do. There could be 10 different ways to achieve it. But the main logic remains - a separate thread is tracking progress throw some device (in this case table).