コード例 #1
0
ファイル: Program.cs プロジェクト: vczh-codeplex/vlpp
        public void StartListeningPort(int port)
        {
            lock (portListeningThreads)
            {
                if (portListeningThreads.ContainsKey(port))
                {
                    throw new InvalidOperationException("Port " + port.ToString() + " has been listened.");
                }

                var serverListener = inFactory.CreateServerListener();
                serverListener.Connect(port.ToString(), TcpShareProviderServiceConfiguration.EndpointName);
                if (serverListener.Connected)
                {
                    Thread          thread          = new Thread(() => PortListeningThreadProc(port, serverListener));
                    ListeningThread listeningThread = new ListeningThread()
                    {
                        Thread         = thread,
                        ServerListener = serverListener,
                    };
                    portListeningThreads.Add(port, listeningThread);
                    thread.Start();
                    return;
                }

                throw new InvalidOperationException("Failed to listen to port " + port.ToString() + ".");
            }
        }
コード例 #2
0
 public void Disconnect()
 {
     ListeningThread.Abort();
     if (Alive)
     {
         TcpClient.Close();
     }
     Disconnected?.Invoke(Id);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: vczh-codeplex/vlpp
        public void StopListeningPort(int port)
        {
            lock (portListeningThreads)
            {
                ListeningThread listeningThread = null;
                if (!portListeningThreads.TryGetValue(port, out listeningThread))
                {
                    throw new InvalidOperationException("Port " + port.ToString() + " has not been listened.");
                }

                listeningThread.Thread.Abort();
                listeningThread.ServerListener.Disconnect();
                portListeningThreads.Remove(port);
            }
        }
コード例 #4
0
 private void Dispose(bool Disposing)
 {
     if (!isDisposed)
     {
         if (Disposing)
         {
             abort = true;
             if (mreSender != null)
             {
                 mreSender.Set();
                 mreSender.Dispose();
             }
             if (mreListener != null)
             {
                 mreListener.Set();
                 mreListener.Dispose();
             }
             if (ListeningThread != null && ListeningThread.ThreadState == ThreadState.Running)
             {
                 ListeningThread.Abort();
             }
             if (ProcessThread != null && ProcessThread.ThreadState == ThreadState.Running)
             {
                 ProcessThread.Abort();
             }
             if (SendingThread != null && SendingThread.ThreadState == ThreadState.Running)
             {
                 SendingThread.Abort();
             }
             if (ServerStream != null)
             {
                 ServerStream.Dispose();
             }
             isDisposed = true;
         }
     }
 }
コード例 #5
0
 public void Start()
 {
     listener = new ListeningThread(this);
     listener.Start();
 }