示例#1
0
        private static void Read()
        {
            Parallel.For(0, 100, (i, state) =>
            {
                if (Thread.CurrentThread.Name == null)
                {
                    var name = new string(Guid.NewGuid().ToString().Where(char.IsLetterOrDigit).ToArray());
                    Thread.CurrentThread.Name = name;
                }

                CountServer.GetCount();
            });
        }
示例#2
0
        private static void Write()
        {
            Parallel.For(0, 50, (i, state) =>
            {
                if (Thread.CurrentThread.Name == null)
                {
                    var name = new string(Guid.NewGuid().ToString().Where(char.IsLetterOrDigit).ToArray());
                    Thread.CurrentThread.Name = name;
                }

                var digit = int.Parse(Guid.NewGuid().ToString().Where(char.IsDigit).First(ch => ch > '0').ToString());
                CountServer.AddToCount(digit);
            });
        }