consider the code below. Each task has components with lifestle per thread. For example ISessionFactory. At some point a thread is reused and if I resolve ISessionFactory or other object with style per thread I will get OLD and obsolete instances. May be Windsor returns object instances based on thread ID which in this case is wrong. The code line where "Thread reused" is written to the console can be container.Resolve<>().
static void Main(string[] args)
{
ConcurrentDictionary<int, int> startedThreads = new ConcurrentDictionary<int, int>();
for (int i = 0; i < 10; i++)
{
for (int x = 0; x < 10; x++)
Task.Factory.StartNew(() =>
{
startedThreads.AddOrUpdate(Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.ManagedThreadId, (a, b) => b);
}, TaskCreationOptions.LongRunning);
for (int j = 0; j < 100; j++)
{
Task.Factory.StartNew(() =>
{
while (true)
{
Thread.Sleep(10);
if (startedThreads.ContainsKey(Thread.CurrentThread.ManagedThreadId))
Console.WriteLine("Thread reused");
}
}, TaskCreationOptions.LongRunning);
}
}
Console.Read();
}