Threading in C#

V

venkat

Hi,
I have a page that calls a sql procedure and it runs for 20 - 40 min. I
use usual threading for this page.

<code>Thread objthread = new Thread(new ThreadStart(ticketingThread));
objthread.Start();</code>

As i dont know when it will end. i never abort the thread. what happens
is when user uses the page for 1 week, the page starts hanging. I dont
know what happens. When i tried debugging it works fine.

I also saw creating thread in threadpools

<code>ThreadPool.QueueUserWorkItem(new
WaitCallback(ticketingThread));</code>

Please advise which one I have to follow and what is the difference
between the two.

Thanks
Venkat
 
T

Tasos Vogiatzoglou

It would be pretty difficult to provide any kind of help for this
problem, as there is no source-code or a more specific indication about
the threading code, application, database.

It could be from a threading race condition to a database lock to
resources exhaustion.

Now, for your second question, by using ThreadPool you pick a thread
from the ThreadPool (whenever and if it's available) and you ensure
that the thread will be returned to the pool and you won't have an
arbitary number of thread running.

What you will follow is a matter of requirements.

Regards,
Tasos
 
V

venkat

Thanks Tasos,
The scenario is I have a button that initiate the ticket processing.
(You can call it like a batch process). It calls a procedure and it
internally calls number of procedures. If the number of items to be
processed is less, then it will take 10-25 min, and max is 40 min. This
is a maintenence work. The existing code works very well but. on due
course the particular page starts hanging. there is no spl code in
that. It has two drop down with two items in it. on slections of those
items user has to click initiate process button. If I restart www
service it starts working fine. that is why I came in to conslusion the
problem is with the threads. (is this correct).

Thanks
Venkat
 
B

Brian Gideon

Venkat,

You said this was maintenance work. Why not just run the stored
procedure as a scheduled job? Why are you calling it from a web page
anyway?

Brian
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Brian Gideon said:
Venkat,

You said this was maintenance work. Why not just run the stored
procedure as a scheduled job? Why are you calling it from a web page
anyway?

Probably cause the parameters change, It's ok to call it from a webpage,
it's not waiting for the result to show in the webpage though.
 
K

Ken

Brian said:
Venkat,

You said this was maintenance work. Why not just run the stored
procedure as a scheduled job? Why are you calling it from a web page
anyway?

Brian
Venkat,

We have a number of processes that take some time to execute. There is
just no way for us to run these things from the web server. If
possible, it is best to run them on a separate processing computer.

We use several queue tables, where the user (or another process)
inserts a request to do something. The process, running on a separate
computer sees this request in the queue, does it's processing and
e-mails the requestor that the process is done.

We tried threads on the webserver but there were many problems. It
just didn't work well. Plus, by placing the heavy-duty processing on
seperate PCs, the web server can do what it does best... Serve web
pages.

Ken - KC7RAD
www.aninetworks.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top