You must have a session context smart enough for a non-web context. But more importantly, the new thread must have its own session.
You can use something like the following:
private ISession threadSession { get { if (HttpContext.Current != null) { return (ISession)HttpContext.Current.Items["THREAD_SESSION"]; } return (ISession)AppDomain.CurrentDomain .GetData("THREAD_SESSION" + Thread.CurrentThread.ManagedThreadId); } set { if (HttpContext.Current != null) { HttpContext.Current.Items["THREAD_SESSION"] = value; } else { AppDomain.CurrentDomain.SetData("THREAD_SESSION" +Thread.CurrentThread.ManagedThreadId, value); } } }
Trent source share