10x Mauricio,
I will try to explain this in more details:

http://stackoverflow.com/questions/13570579/is-it-possible-always-to-force-a-new-thread-with-task

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();
        }


-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/castle-project-users/-/qEjQP16kks8J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to