public void Connect(String hostname, int port) { logger.Debug("Connecting..."); try { _destination = new Address(port); _destination.IP = IPAddress.Parse(hostname); } catch (FormatException) { _destination = Address.Resolve(hostname, port); } logger.Debug(_destination.EndPoint); _client.Connect(_destination.EndPoint); logger.Debug(_client.Connected); _reader = XmlReader.Create(_client.GetStream()); _thread = new Thread(new ThreadStart(new ThreadSocket().ThreadConnect)); _thread.IsBackground = true; _thread.Start(); logger.Debug(_thread.IsAlive); if (Connection != null) { Connection(); } } private void ThreadConnect() { logger.Debug("In thread..."); ProtocolParser parser = new ProtocolParser(_reader); parser.DocumentEnd += new ObjectDelegate(parser_DocumentEnd); parser.DocumentStart += new TagDelegate(parser_DocumentStart); parser.Element += new TagDelegate(parser_Element); parser.Parse(null, null); }