We help IT Professionals succeed at work.
Get Started

Run tasks synchronously in background thread

Last Modified: 2017-05-02
I have a c# rules based application which is running a transaction which runs an SQL statement oven a large file. I want to run the final parts of the transaction as a background job. So for example seq 1 – 8 below are gathering data selection details and  seq 9 – 10 are running the SQL statement and emailing the results back. Step 9 & 10 are independent steps and therefore need to be run synchronously in a background job.

Seq      operation              comment
1      Get user email                      Interactive
2      Get list of items                      Interactive                
3      Get date range                      Interactive                
4      ..                                              Interactive
5      ..                                              Interactive
6      ..                                              Interactive
7      ..                                              Interactive                
8      Configure SQL statement   Interactive          
9      Run SQL Statement              Background job synchronously,  (populate datatable with result of the SQL statement)
10      Email results to user           Background job synchronously,  (emails results of SQL statement)

This command will email the results to the user email address. It should only run once Seq 9 is complete

11      GOTO Seq 1      Interactive

I have tried looking at task.RunSynchronously   but this seems to run 10 & 11 in UI rather than in a background task. I have also looked a Background worker but it doesn't seem to have the ability to run synchronously. Appreciate if someone can suggest the best way to achieve what I am trying to do. If you can give an example - that would be great.

Watch Question
Freelance programmer / Consultant
This problem has been solved!
Unlock 5 Answers and 19 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE