I am developing a PC WinForms application in C# that needs to connect to a microcontroller later. For now, for testing purposes, I have created a virtual null modem on my computer and linked it with a terminal program.
The virtual null modem I'm using is "com0com": http://sourceforge.net/projects/com0com/
Here is a screenshot of the COM port pair settings:

In my application I use the component serialPort. This is how the serialPort is set up:
public bool SerialPortSetup(String cp)
{
String port = cp;
int baud = 19200;
Parity parity = Parity.None;
int databit = 8;
StopBits stopbit = StopBits.One;
try
{
// Initialize serial port
serialPort1 = new SerialPort(port, baud, parity, databit, stopbit);
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPortDataReceived);
serialPort1.Open();
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
}
Other properties of the serialPort:

The terminal program that I've connected to COM2 is set up with the same baudrate, parity, databit, stopbit, etc. When I have connected my own app to COM1, and the terminal to COM2, it all works just fine. Both writing and reading in both directions.
However, when I don't use the COM2 port (that is, the terminal program is not opened), my app hangs just the second I start to use serialPort1.Write(str), where str is just a random string. When running my app from Visual Studio, I can only close it by stopping the debugging. It's not like Windows marks it as "not responding". Btw, I always check for an opened serialPort before I write to it.
I need this problem to go away. Ideas?