c# - Thread not ending possible that exceptions cause this? -
i'm starting multiple threads different things. threads have "endme" boolean variable. when try end threads setting variable , end debugger screams not end processes.
after debugging bit found out processes go "ending" part of code when "end me" variable set accordingly. exception happens , thrown.
now question is: can exception causes thread not able ended longer?
promoting comment answer since correct , might relevant.
in absence of code reproduce problem, note if communicating between threads setting boolean variable "endme", need use volatile reads , writes access variable, instance (in .net 4.5):
public class threadedworker { bool endme = false; public bool endsignalled { { return volatile.read(ref endme); } } public void signalend() { volatile.write(ref isended, true); } }
or in c# versions can use volatile
keyword
public class threadedworker { volatile bool endme = false; public bool endsignalled { { return endme; } } public void signalend() { endme = true; } }
Comments
Post a Comment