multithreading - c# Background thread gets an error when run in UserControl -
right in usercontrol, have button click event starts thread. i've since moved on using abort(), , trying convert thread background process shut down when close parent form. code is:
public thread t; private void btninitiate_click(object sender, eventargs e) { udplistener mylistiner = new udplistener(this); t.isbackground = true; t = new thread(() => mylistiner.spreadvalue(mycurrentport, firstticker, secondticker, mybeta)); t.start(); }
but when run application, error t.isbackground=true
says "object reference not set instance of object". i'm wondering going wrong in case.
you need change row order in code:
... t = new thread(() => mylistiner.spreadvalue(mycurrentport, firstticker, secondticker, mybeta)); t.isbackground = true; ...
because need instantiate thread , use it.
Comments
Post a Comment