Question: I am connecting to Gmail account using TCP client for reading emails. It returns SslStream for the TCP connection. It works fine for single thread environment but performance is very poor in terms of speed. 

I need to optimize the project so that its speed can be increased. I have implemented multithreading which increases the speeed but application gets hang at some point. 

Is it thread safe to use TCP connection (global member)?

OR Can I create multiple TCP connections and pass to the thread method to increase the speed ?

OR is there any other better way for doing this?

```
TCPClient m_TCPclient
SslStream sslStream;

private void createTCP()
{
// creating tcp and sslstream
}

private void authenticateUser()
{
// authenticating the user
}

private void getUserdata()
{

// iterating folders and its items
foreach(string emailID in IDList)
{
//Thread implementation

}

```

Answer: 
You can use output redirection to run whatever command you need:

```
mongo localhost:27017 <<< $'rs.slaveOk()\nshow dbs'

```

or 

```
echo $'rs.slaveOk()\nshow dbs' | mongo localhost:27017

```

just remember the `\n` between commands.
Use `--authenticationDatabase` to authenticate to the database where your user exists even though you are connecting to a different database:

```
mongo localhost:27017/dev -u user -p **** --authenticationDatabase admin

```

Naturally, you won't be able to do anything in the `dev` database your user doesn't have permissions to do.