views:

51

answers:

0

We're trying to develop a windows service in vs2008 .net that uses sql notification services to detect changes to a table. When there's a change in the table, the helper class within the window service app will make changes to other tables, and then delete the entries in the table that Im using the sqldependency object to monitor. When making the changes Im using enterprise services' contextutil begintrans, setcomplete, and setabort and LINQ.

On the window service onstart procedure, I plan on using something similiar to:

public class MyService{    
    public void StartService()    {        
         Thread listener = new Thread(Listen);        
         listener.IsBackground = true;        
         listener.Start();    
   }    

   private void Listen()    {        
         while (true)        {  

           ...
        }
   }

question 1) Do I need to make a singleton wrapper class for the contextutil object so it it thread safe and can be used by the listener thread

question 2) what I'm struggling with is how to deal with the situation when the service is stopped midway through a sql transaction. How would I pass in the contextutil object into the service onstop event handler and check that the IsInTransaction returns true, if it does, then call the contextutil.setabort to rollback the transaction. Do I use the singleton contextutil object described in question 1) to check for the isintranaction() state