Thx,
I was almost sure this was a bad idea ;)
What I'm trying to do is to propose to our users via a web interface
the capability to load 5 or 6 really huge XML files( > 100 Mb each) in
the App database (doing XSL tranform and then bulk inserts to sql
server). This should be done on demand almost immediatly since they do
not want to wait for any kind of batch or whatever. Once those files
are loaded, they can then perform comparisons and a lot of other
tasks.
On our end, the import job take around 13 minutes to complete but on
the user side, they are experiencing TCP problems (the connection is
lost but the job is indeed still running!!) . I though about this
threading approach essentially thinking of having a running thread
separate from the ASP.NET one so that users won't loose the HTTP
connection. I agree this is the bad way to solve the problem and maybe
an aynchronous Web service will do the trick. What do you think of
that? Any ideas, comment, code to share?
Regards and nice we :)
Philippe GRACA
"John Saunders" <jo************ **@hotmail.com> wrote in message news:<O3******* *******@TK2MSFT NGP14.phx.gbl>. ..
"Phil" <ph************ @hotmail.com> wrote in message
news:78******** *************** ***@posting.goo gle.com... Hi,
I've a simple page with one button.
In the OnClick event, I want to create a thread that will perform a
long runninf task.
Here is a sample code
in the OnClick
Thread t = new Thread(new ThreadStart(thi s.Import));
t.Priority = ThreadPriority. Lowest;
t.Start();
Import Function
public void Import()
{
for (int i=0;i<100;i++)
{
Response.Write( i.ToString() + "<br>");
Thread.Sleep(10 0);
}
}
The issue is that my thread stop working really quickly. In this
example, the thread only display figures from 0 to 9... instead of
100...
Is there something special I should now about running threads in
asp.net?
Philippe, the basic thing to know about threads and ASP.NET is - don't use
threads with ASP.NET.
The only truly safe ways to use threads with ASP.NET involve the threads
being totally independant of the request which spawned them. Your thread is
obviously dependant on the request, as it want to output more HTML to the
response.
John Saunders
P.S. The basic reason is that:
1) the request comes in, creating some objects like Request, Response and
Page.
2) Your thread then starts running, writing to Response.
3) The request terminates, destroying and/or invalidating all of the objects
like Request, Response and Page.
4) Your thread continues as though Request, Response and Page were still
valid, which - they're not...