Hello,
I don't have at hands a dev environment to test it,
so I can give you only generic advices.
First of all, why do you write the initialization statements in the button2_click procedure ?
I would move it in the constructor, just after initialize_components.
that is :
public Form1()
{
InitializeComponent();
port.BaudRate = 9600;
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
}
After that you should remove the Application.run() statement from the button2.click statement.
Application.Run() should be called just after having created the main form,
from the application main procedure so that the application can correctly handle any events that happens to it.
Third, try to understand what the error message say and let us know about it.
Fourth, how can the sender of the data knows it is time to send it ?
There is a kind of 'protocol' between this application and the sender ?
Does the sender reply to a message sent to it by this application or it sends data asynchronously ?
If this is the case, you should leave the port open all the time, that is, open it at program start and close it at program termination.
Best regards.
Maurizio.