I’ve created a asp.net page which execute a very long sp (about 1 hour of sp execution time in SSMS).
there is an Admin.aspx which activate this SP.
in web.config I’ve added:
<httpRuntime maxRequestLength="111264" requestValidationMode="2.0" executionTimeout="10000000" />
also in the connection properties Ive added :
_cmd.CommandTimeout = 0; // unlimited
the function is using jquery ajax (to ashx) to activate the sp (it is working and fine)
the jquery calls an ashx file which activate the sp .
However I didn’t want the the UI will be blocked till the end of the operation so i created a thread in the ashx file :
public void ProcessRequest(HttpContext context)
{
string xmlFileNameParam = ...
string bakFileName = ...
ParameterizedThreadStart ThreadWithParam = dbFuncForThread;
Thread thread = new Thread(ThreadWithParam);
thread.IsBackground = false;
dynamic d = new ExpandoObject();
d.XmlFileNameParam = xmlFileNameParam;
d.BakFileName = bakFileName;
thread.Start(d);
}
public void dbFuncForThread(dynamic d)
{
// activate the long sp
}
However after a while , i see this error in the EventLog (and the operation stopped):**
There is a problem line 259Thread was being aborted.
at System.Threading.Thread.SleepInternal(Int32 millisecondsTimeout)*
Why?
I gave the thread all the environment it needed (connection timeout, execution timeout)
P.S.
If I don’t use a thread and put a normal code like this (UI Is blocked though):
public void ProcessRequest(HttpContext context)
{
string xmlFileNameParam = ...
string bakFileName = ...
dynamic d = new ExpandoObject();
d.XmlFileNameParam = xmlFileNameParam;
d.BakFileName = bakFileName;
dbFuncForthread(d);
}
public void dbFuncForThread(dynamic d )
{
// activate the long sp...
}
So the code is fine and everything is fine. How and why is that and how do I solve it?
I think you may reconsider your design, better use windows service to do this for you. From webservice pass data to windows service which thn execute sp. The obvious problem for this scenario in web environment couldbe IISReset or appdomain recycle will abort all threads.