예제 #1
0
 public bool CheckFileInUse(string fileName)
 {        //检测文件是否正在使用中,如果正在使用中则检测是否被上传协议占用,如果占用则关闭,真表示正在使用中,并没有关闭
     if (BasicFunc.IsFileInUse(fileName))
     {
         bool result = true;
         lock (m_asyncSocketServer.UploadSocketProtocolMgr)
         {
             UploadSocketProtocol uploadSocketProtocol = null;
             for (int i = 0; i < m_asyncSocketServer.UploadSocketProtocolMgr.Count(); i++)
             {
                 uploadSocketProtocol = m_asyncSocketServer.UploadSocketProtocolMgr.ElementAt(i);
                 if (fileName.Equals(uploadSocketProtocol.FileName, StringComparison.CurrentCultureIgnoreCase))
                 {
                     lock (uploadSocketProtocol.AsyncSocketUserToken) //AsyncSocketUserToken有多个
                     {
                         m_asyncSocketServer.CloseClientSocket(uploadSocketProtocol.AsyncSocketUserToken);
                     }
                     result = false;
                 }
             }
         }
         return(result);
     }
     else
     {
         return(false);
     }
 }
예제 #2
0
 //检测文件是否正在使用中,如果正在使用中则检测是否被上传协议占用,如果占用则关闭,真表示正在使用中,并没有关闭
 public bool CheckFileInUse(string fileName)
 {
     if (BasicFunc.IsFileInUse(fileName))
     {
         bool result = true;
         lock (m_asyncSocketServer.DownloadSocketProtocolMgr)
         {
             DownloadSocketProtocol downloadSocketProtocol = null;
             for (int i = 0; i < m_asyncSocketServer.DownloadSocketProtocolMgr.Count(); i++)
             {
                 downloadSocketProtocol = m_asyncSocketServer.DownloadSocketProtocolMgr.ElementAt(i);
                 if (fileName.Equals(downloadSocketProtocol.FileName, StringComparison.CurrentCultureIgnoreCase))
                 {
                     lock (downloadSocketProtocol.AsyncSocketUserToken) //AsyncSocketUserToken有多个线程访问
                     {
                         m_asyncSocketServer.CloseClientSocket(downloadSocketProtocol.AsyncSocketUserToken);
                     }
                     result = false;
                 }
             }
         }
         return(result);
     }
     else
     {
         return(false);
     }
 }