Sunday, 15 September 2013

c# - halt in backgroundworker thread when using scintilla NET to not freeze the GUI -



c# - halt in backgroundworker thread when using scintilla NET to not freeze the GUI -

the background worker halts when invoked append text scintilla controls, here partial code. after adding seek grab logic, still didn't exceptions!

private delegate void dwrite(string text); private void write(string text) { seek { scintilla1.appendtext(text); } grab (exception ex) { messagebox.show(ex.tostring()); } } private void bw_dowork(object sender, doworkeventargs e) { backgroundworker worker = sender backgroundworker; string x; while (true) { x = tcw.read(); // messagebox.show(x); thread.sleep(100); seek { scintilla1.invoke(new dwrite(write), x); } grab (exception ex) { messagebox.show(ex.tostring()); } // scintilla1.update(); }

i added logic:

static void myhandler(object sender, unhandledexceptioneventargs args) { exception e = (exception)args.exceptionobject; messagebox.show("myhandler caught : " + e.message); } public void doworkstuff() { appdomain currentdomain = appdomain.currentdomain; currentdomain.unhandledexception += new unhandledexceptioneventhandler(myhandler); seek { (int = 0; < 5; i++) scintilla1.invoke(new dwrite(write), tcw.read()); } grab (exception ex) { messagebox.show(ex.tostring()); } }

the problem seems command self, not allowing external threads access avoid deadlocks. there way can same functionality without having utilize bgworker? tcw.read() telnet client streams input control, want streaming (i.e. tcw.read()) go on until users presses stop on form!

you've found bug in scintillanet.

to handle interop between managed scintilla wrapper , native scintilla control, scintillanet overrides wndproc method. in doing, appears windows forms mechanism marshaling calls ui thread has been broken.

in meantime, can utilize backgroundworker.progresschanged event there exactly type of periodic ui update attempting.

after making sure you've set backgroundworker.workerreportsprogress property true, modify code utilize backgroundworker.reportprogress method in place of invoke method , handle progresschanged event.

private void bw_dowork(object sender, doworkeventargs e) { backgroundworker worker = sender backgroundworker; string x; while (true) { x = "your telnet data"; thread.sleep(100); worker.reportprogress(-1, x); } } private void bg_progresschanged(object sender, progresschangedeventargs e) { string text = e.userstate string; scintilla1.appendtext(text); }

(full disclosure: i'm scintillanet developer)

c# multithreading user-interface backgroundworker scintilla

No comments:

Post a Comment