Ejemplo n.º 1
0
 /// <summary>
 /// 检查客户端连接
 /// </summary>
 private void CheckCon()
 {
     while (true)
     {
         if (DTU_ClientManager.Clients != null)
         {
             int len = DTU_ClientManager.Clients.Count;
             for (int i = len - 1; i >= 0; i--)
             {
                 using (MyLock mylock = new MyLock(DTU_ClientManager.Clients[i], 5000, false))
                 {
                     if (mylock.IsTimeout == false)
                     {
                         try
                         {
                             int n = DTU_ClientManager.Clients[i].socket.Send(new byte[] { 1 }, SocketFlags.None);
                         }
                         catch (Exception e)
                         {
                             DTU_ClientManager.DeleteClient(DTU_ClientManager.Clients[i]);
                         }
                     }
                 }
             }
         }
         Thread.Sleep(20000);//
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 关闭服务
        /// </summary>
        /// <param name="serviceName">服务名称</param>
        /// <param name="sender">关闭服务按钮</param>
        /// <param name="start">开启服务按钮</param>
        public static void StopService(string serviceName, object sender, object start)
        {
            Button btnStop = sender as Button;
            Button btnStart = start as Button;
            MyLock myLock = new MyLock();
            if (btnStop != null && btnStart != null)
            {
                btnStop.Text = "Stopping...";
                btnStop.Enabled = false;
                //关闭MSSQLSERVER服务
                ThreadPool.QueueUserWorkItem(a =>
                {
                    lock (myLock)
                    {
                        Thread.Sleep(3000);
                        Service.ServiceName = serviceName;
                        Service.Stop();

                        while (true)
                        {
                            if (ServiceState(serviceName) == false)
                            {
                                btnStop.Enabled = true;
                                btnStop.Text = "Stop";
                                btnStop.Enabled = false;
                                btnStart.Enabled = true;
                                break;
                            }
                        }
                    }
                });
            }
        }
Ejemplo n.º 3
0
 public void Unlock(ILock _lock)
 {
     if (_lock != this._lock)
     {
         throw new ArgumentException("Invalid lock used to unlock", "_lock");
     }
     Monitor.Exit(_lock.Sync);
     this._lock = null;
 }
Ejemplo n.º 4
0
 public ILock Lock()
 {
     if (_lock != null)
     {
         throw new InvalidOperationException("Already locked.");
     }
     _lock = new MyLock(this);
     Monitor.Enter(_lock.Sync);
     return(_lock);
 }