c# - Can't add strings to listbox -
hi i'm trying collect output of this library listbox.
here's part of code test project, i've tried modify:
public partial class form1 : form { d.net.clipboard.clipboardmanager manager; public form1() { initializecomponent(); manager = new d.net.clipboard.clipboardmanager(this); manager.type = d.net.clipboard.clipboardmanager.checktype.text; manager.onnewtextfound += (sender, eventarg) => { button1.text = eventarg; //just testing, working correctly listbox1.items.add(eventarg); //does not show neither result nor error messagebox.show(string.format("new text found in clipboard : {0}", eventarg)); }; } private void button1_click(object sender, eventargs e) { listbox1.items.add("test"); //working correctly } }
problem when trying add item list nothing, , further lines of code (in function) don't run @ all.
i tried fix thru custom classes , different expressions nothing worked me (yes, i'm noob). tried textbox, result same, text on buttons changes should.
looks lame problem, i've spent 5 hours googling, reading microsoft documentation, so, , closest can this can see stuff suggested there implemented.
the onnewtextfound
event firing on separate thread ui, attempt update ui failing. exception thrown in other thread, aborting rest of method, ui thread keeps executing.
you'll have call invoke()
in order execute code on ui thread:
listbox1.invoke(new methodinvoker(delegate { listbox1.items.add(eventarg); }));
Comments
Post a Comment