troubleshooting Question

Run tasks synchronously in background thread

Avatar of pclarke7
pclarke7 asked on
C#* multithreading* Background worker
19 Comments5 Solutions548 ViewsLast Modified:
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.

Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 5 Answers and 19 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 5 Answers and 19 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros