private void Form1_Load(object sender, EventArgs e) { _serialport.DataReceived += new SerialDataReceivedEventHandler(_serialport_DataReceived); _serialport.PortName = "COM4"; _serialport.BaudRate = 9600; _serialport.DataBits = 8; _serialport.Parity = Parity.None; _serialport.StopBits = StopBits.One; _serialport.Open(); } private delegate void SetTextDeleg(string text); private void _serialport_DataReceived(object sender, SerialDataReceivedEventArgs e) { string data = _serialport.ReadExisting(); // Invokes the delegate on the UI thread, and sends the data that was received to the invoked method. // ---- The "si_DataReceived" method will be executed on the UI thread which allows populating of the textbox. this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data }); timer1.Enabled = true; } private void si_DataReceived(string data) { textBox1.Text = data.Trim(); timer1.Enabled=true; } private void timer() { if (textBox1.Text == "makan") timer1.Enabled = true; } private void timer1_Tick(object sender, EventArgs e) { if (sec > 58) { min++; sec = 0; } else { sec++; } if (min == 2 && sec > 29) { lblTime.ForeColor = Color.Red; } if (min == 3) { min = 3; sec = 0; lblTime.Text = string.Format("{0:00} : {1:00}", min, sec); timer1.Enabled = false; } lblTime.Text = string.Format("{0:00} : {1:00}", min, sec); }