c# - Is it guaranteed that a thread will complete in aspnet? -
c# - Is it guaranteed that a thread will complete in aspnet? -
i have simple code in aspnet :assuming no exceptions nor file locking nor process terminates :
new thread(()=>{ thread.sleep(15000); // gc.collect(); file.write (...); // dummy file }).start(); // gc.collect(); from tests , file always created.
question
scenario not understood me request lifetime much shorter thread execution , still works . thats . thats main question
is guaranteed file created ?
nb it's test examine behavior . page empty page code. know bring together wait
it not. when iis decides recyle entire process take downwards both background , foreground threads. see this answer.
luckily, can create sure not interrupted. can tell asp.net thread implementing iregisteredobject interface. can register object using hostingenvironment.registerobject. see the dangers of implementing recurring background tasks in asp.net
c# asp.net multithreading
Comments
Post a Comment