c# - creating a new row in ListView and then writing to COM port delayed ListView loadtime, solution? -
the listview renders row item quite fast @ normal state. when call function write com port (pole display) . load time of list view increases , slows down whole process. i've first called function add item listview. list view uses addrange method add items. vfd function called open com port first , initialize port write port.
here full sample code:
//function add new row item in listview private void listfunction(int id) { listviewitem checkitem = listview1.finditemwithtext(getproduct(id)); if (checkitem != null) { //messagebox.show("it exist"); int itemvalue = int.parse(checkitem.subitems[2].text) + 1; checkitem.subitems[2].text = itemvalue.tostring(); int ttlamt = getprice(id) * int.parse(checkitem.subitems[2].text); string totalamount = ttlamt.tostring(); checkitem.subitems[4].text = totalamount; } else { // if doesnot exist int ttlamt = getprice(id); listviewitem item1 = new listviewitem("1"); item1.subitems.add(getproduct(id)); item1.subitems.add("1"); item1.subitems.add(getprice(id).tostring()); string totalamount = ttlamt.tostring(); item1.subitems.add(totalamount); listview1.items.addrange(new listviewitem[] { item1 }); } // write port public void vfd(int id) { serialport vfd = new serialport("com5", 9600, parity.none, 8, stopbits.one); vfd.open(); vfd.write(initialize); vfd.write(getproduct(id) + ":" + getprice(id)); vfd.write("\x1b\x6c\x09\x02"); vfd.write("total: " + totalamt.text); vfd.close(); } private void button1_click(object sender, eventargs e) { int id = 10001; //add list listfunction(id); // vfd display vfd(id);; }
all of items called database.
this slows down list render performance.
how rid of this?
you send data com port on separate thread 1 isn't held up, careful make code thread-safe.
Comments
Post a Comment