Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Test()
- {
- var items = new List<EntityA>();
- for (int i = 0; i < 100000; i++)
- {
- items.Add(new EntityA { FirstName = "A" + i });
- }
- ManualResetEvent stopChangingMappingFunction = new ManualResetEvent(false);
- Thread t1 = new Thread(() =>
- {
- int i = 1;
- while (true)
- {
- if (stopChangingMappingFunction.WaitOne(TimeSpan.Zero))
- return;
- var i1 = i++;
- Mapper.CreateMap<EntityA, EntityB>().ForMember(x => x.Age, y => y.ResolveUsing(new Func<EntityA, object>(a => i1)));
- }
- });
- Thread t2 = new Thread(() =>
- {
- int i = -1;
- while (true)
- {
- if (stopChangingMappingFunction.WaitOne(TimeSpan.Zero))
- return;
- var i1 = i--;
- Mapper.CreateMap<EntityA, EntityB>().ForMember(x => x.Age, y => y.ResolveUsing(new Func<EntityA, object>(a => i1)));
- }
- });
- List<int> distinctAges1 = null;
- List<int> distinctAges2 = null;
- Thread t3 = new Thread(() =>
- {
- Thread.Sleep(1000);
- var res = Mapper.Map<IList<EntityA>, IList<EntityB>>(items);
- distinctAges1 = res.Select(x => x.Age).Distinct().ToList();
- Thread.Sleep(1000);
- var res2 = Mapper.Map<IList<EntityA>, IList<EntityB>>(items);
- distinctAges2 = res.Select(x => x.Age).Distinct().ToList();
- stopChangingMappingFunction.Set();
- });
- t1.Start();
- t2.Start();
- t3.Start();
- t1.Join();
- t2.Join();
- t3.Join();
- Console.WriteLine("First Mapping: " + string.Join(", ", distinctAges1.ToArray()));
- Console.WriteLine("Second Mapping: " + string.Join(", ", distinctAges2.ToArray()));
- Console.ReadKey();
- }
- public class EntityA
- {
- public string FirstName { get; set; }
- }
- public class EntityB
- {
- public string FirstName { get; set; }
- public int Age { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement