i have simple win-form 2 buttons on , 1 button start , 1 stop thread.
but, when press stop button encounter error : "thread being aborted."
what wrong codes?
thread th_modesendingworks; private void buttonstart_click(object sender, eventargs e) { th_modesendingworks = new thread(new threadstart(works)); th_modesendingworks.start(); } private void buttonstop_click(object sender, eventargs e) { th_modesendingworks.abort(); textbox1.appendtext("------------------"); } private void works() { try { while (th_modesendingworks.isalive) { textbox1.begininvoke((methodinvoker)delegate() { textbox1.appendtext("xxxxxxxxxxx"); textbox1.scrolltocaret(); }); thread.sleep(1000); } } catch (exception err) { textbox1.begininvoke((methodinvoker)delegate() { textbox1.appendtext("err:" + err.message); textbox1.scrolltocaret(); }); } }
it's normal?
yes...as user1274820 mentioned, see thread.abort:
when method invoked on thread, system throws threadabortexception in thread abort it.
Comments
Post a Comment