Exemple #1
0
        private void button22_Click(object sender, EventArgs e)
        {
            if (this.tryLocking2)
            {
                return;
            }

            if (this.locked2)
            {
                return;
            }

            this.tryLocking2 = true;

            Thread thread = new Thread(
                () =>
            {
                this.Invoke(new Action <string>(this.WriteMsg), new object[] { "线程 2  TryLock .." });

                Helper helper = new Helper("127.0.0.1", 9527);

                lockId2 = helper.TryLock("testLog");


                while (true)
                {
                    if (lockId2 != null)
                    {
                        break;
                    }

                    Thread.Sleep(1);

                    lockId2 = helper.TryLock("testLog");
                }


                this.tryLocking2 = false;
                this.locked2     = true;

                this.Invoke(new Action <string>(this.WriteMsg), new object[] { "线程 2  TryLock success ." });
            }
                );

            thread.Start();
        }