private void AcceptCallback(IAsyncResult ar)
        {
            try
            {
                // Signal the main thread to continue.
                connectDone.Set();

                // Get the socket that handles the client request.
                Socket listener = (Socket)ar.AsyncState;
                Socket handle = listener.EndAccept(ar);

                // Create the state object.
                TcpDataObject state = new TcpDataObject();
                state.workSocket = handle;

                handle.BeginReceive(state.buffer, 0, TcpDataObject.BufferSize, 0,
                    new AsyncCallback(ReadCallback), state);
                //receiveDone.WaitOne();
            }
            catch (ObjectDisposedException ode)
            {
                Logger.LogException("Catched ObjectDisposedException", ode);
            }
            catch (Exception e) when (e is ArgumentException || e is SocketException || e is InvalidOperationException || e is NotSupportedException)
            {
                Logger.LogException("Catched other specific exception", e);
            }
        }
        private void Receive(Socket client)
        {
            try
            {
                //receiveDone.Reset();
                // Create the state object.
                TcpDataObject state = new TcpDataObject();
                state.workSocket = client;

                // Begin receiving the data from the remote device.
                client.BeginReceive(state.buffer, 0, TcpDataObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);
                receiveDone.WaitOne();
            }
            catch (ObjectDisposedException ode)
            {
                Logger.LogException("Catched ObjectDisposedException", ode);
            }
            catch (Exception e)
            {
                Logger.LogException("Catched other exception", e);
            }
        }