Is Solver Foundation Safe to Use in a Web Application

Answered Is Solver Foundation Safe to Use in a Web Application

  • Thursday, December 15, 2011 11:12 PM
     
     

    I've been looking for a while and failed to find a definitive answer... is it safe to use SFS from a web application or web service where the host machine could be dealing with a number of requests in parallel? I ask because the help for the SolverContext.GetContext() method says "Returns the singleton context" which to me implies a single shared context between all executing threads. Is that OK? Surely because Solve() is called on the context there will be problems if two threads are setting up a Model? or is the context thread specific?

    I'm sure I'm just missing something obvious here!


    • Edited by Piers Lawson Friday, December 16, 2011 12:46 AM
    •  

All Replies

  • Saturday, December 17, 2011 4:01 AM
     
     Answered

    The answer to your broader question is yes - it's safe to use the SFS in this way. You should be able to use GetContext() and things should work out okay.

    In any case, if for some reason you were to run into a problem, it shouldn't matter because in Solver Foundation 3.1 it is possible to create multiple SolverContext instances, see:

    http://msdn.microsoft.com/en-us/library/microsoft.solverfoundation.services.solvercontext.solvercontext%28v=VS.93%29.aspx

    Nate

    • Proposed As Answer by Nate Brixius Saturday, December 17, 2011 4:01 AM
    • Marked As Answer by Piers Lawson Saturday, December 17, 2011 4:01 PM
    •  
  • Saturday, December 17, 2011 4:01 PM
     
     Answered

    I was hoping for a more definitive answer than "should be able".... I have now fired up reflector and it appears that GetContext uses System.Runtime.Remoting.Messaging.CallContext to store an instance of SolverContext. Generally this means a new SolverContext will be created per request, though there are circumsatnces in which the CallContext can be lost between different stages of the ASP.Net pipeline. However, this would result in loss of your model rather than sharing of the SolverContext between different resquests. You are also right Nate that it appears I can now just construct a new Solver whenever necessary.

    Thanks


    • Marked As Answer by Piers Lawson Saturday, December 17, 2011 4:01 PM
    • Edited by Piers Lawson Saturday, December 17, 2011 4:02 PM
    •