Port details class
public static class PortDetails
{
private static bool portOpen;
private static bool portClose;
public static void OpenPort()
{
if (portClose)
{
portOpen = true;
portClose = false;
}
}
public static void ClosePort()
{
if (portOpen)
{
portClose = true;
portOpen = false;
}
}
}
Form1 code behind
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
PortDetails.OpenPort();
}
catch (Exception ex)
{ }
}
}
Form2 code behind
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
PortDetails.ClosePort();
}
}