c# - serialport pinchanged event's weird behaviour -
i using rfid reader/writer uses serial port. trying make program work if unplugs serial port , plugs again. serial port pinchanged event allow me know if serial port unplugged,at point start timer tries connect serial port every 1 second , if plugged again starts serial port. seems working fine there 1 problem works if put breakpoint on pinchanged event handler , not work otherwise. works if put messagebox.show() in serialport pinchanged event. below code
private void serialport1_pinchanged_1(object sender, serialpinchangedeventargs e) { messagebox.show("serialport changed event type" + e.eventtype.tostring()); if ((e.eventtype == serialpinchange.ctschanged || e.eventtype == serialpinchange.dsrchanged) && !serialport1.isopen) { this.invoke(new methodinvoker(delegate() { timertoreconnectdevice = new system.windows.forms.timer(); timertoreconnectdevice.interval = 1000; timertoreconnectdevice.tick += new eventhandler(timertoreconnectdevice_tick); timertoreconnectdevice.enabled = true; timertoreconnectdevice.start(); })); } }
Comments
Post a Comment