I have a WCF Service written in C# which makes extensive user of global variables. The Service runs menus and transaction which are made up of sequenced database records with each database record capable of calling specific logic based on inbuilt commands. A typical simplistic example could be:
10 Display Screen
20 Input Range of Items
30 run SQL statement to retrieve item details from Item master table
40 Display Item Details
50 Confirm selected Items
*60 Run SQL statement to report on Item Usage
*70 Output SQL results to CSV
*80 Email usage report to user
90 Goto Start
Those marked with * should run in a background thread so that after seq 50 the user will be returned to seq 05 whilst the background thread takes over. The issue I have is that Many of the variables controlling the transactions are global variables and so when the user returns to 05 and then exists to a new transactions this effects the background job since the background job is running the same code as the UI , except in the background thread.
I have copied all of the variables from UI to the background thread however the UI continues to update these global background thread variables after the background thread is launched. How can I stop the UI from affecting the background thread global variables ?