Using a single session in multiple threads is likely a bug

NHibernate Profiler has detected a session that is used in a different thread than the one it was opened on.

NHibernate sessions are not thread safe, and attempting to use them in multiple threads requires careful synchronization. It is generally better to consider a session only useful within the thread that created it.

There are valid scenarios for cross thread session usage (background loading with careful sync, multi request spanning session), but usually this alert indicate a problem in serializing access to the session.

The following code will trigger the alert:

using(var session = factory.OpenSession())
{
var wait = new ManualResetEvent(false);

//simulating work on the session using a different thread...
ThreadPool.QueueUserWorkItem(state =>
{
using(var tx = session.BeginTransaction())
{
session.Get<Blog>(1);

tx.Commit();
}

wait.Set();
});

wait.WaitOne();
}

If you are using the session across multiple threads intentionally and are certain that you are correctly serializing access to it, then you can safely ignore this alert.

You can also disable this alert completely in the options dialog.