Solved

How to control a thread

Posted on 2011-02-23
6
371 Views
Last Modified: 2013-12-17
Hello,

  I'm trying to create a thread in a ASP.NET site, where the user can start the thread and it keeps working up to its end even if the user leaves the site. The code I write is:

   GenerateOLAPData god = new GenerateOLAPData(_description, _fromDate, _toDate);
   Thread thread = new Thread(god.OLAPGenerator);
   thread.Start();

   GeraneteOLAPData connects to a database, setup the parameters and runs a long thread, populating a table with many records.

  It starts to work but sometime later the thread stops. Is there a timeout for it? How can I keep it working even if the user leaves the site?

  Thanks,

  Marco Castro
0
Comment
Question by:MarcoCastro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:MarcoCastro
ID: 34966949
In a experience, if I go to the site during the thread process it stops faster. If I don't get in the site the thread keeps working!
0
 
LVL 51

Assisted Solution

by:Ted Bouskill
Ted Bouskill earned 166 total points
ID: 34971726
This isn't a good design.  When the page cycle ends and the last bytes are sent to the user all foreground threads are destroyed.  You can launch a background thread but it's orphaned and could be recycled by the application pool at any time based on the load of the server.

If you are using MS SQL fire up a SQL Agent job to execute the work from your code.
0
 
LVL 11

Accepted Solution

by:
Sudhakar Pulivarthi earned 167 total points
ID: 34978832
Hi,
I thread gets terminated when the code/method assign to it is completed. or The process which launched the thread is closed which will terminate all the threads assosiacted for the process. No timeouts

For your requirement. Its better to run a exe instead of a thread with in a process. When u launch a process it will run with out depending on the parent process launched it.

Check out this conversation:
http://www.velocityreviews.com/forums/t99961-thread-timeout.html
0
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
LVL 8

Assisted Solution

by:Volox
Volox earned 167 total points
ID: 35040124
I agree that this isn't the best design, but if you want the thread to keep working after the page and or session have completed, you will need to store the thread in a static variable.  And if you have the need for more than one thread (different users start their own thread) then you will need to use a static threadsafe collection that you key by some identifier for the user.
0
 

Author Closing Comment

by:MarcoCastro
ID: 35341901
The answers was so superficial
0
 
LVL 8

Expert Comment

by:Volox
ID: 35343557
MarcoCastro,

How is giving you advice that your thread variable needs to be a static varaible 'superficial' advice?  And if you needed an example of having one thread per user, you should have posted back and asked for it.  I don't think it is appropriate to give people's answers poor ratings if you aren't willing to post asking for clarifications or further information.
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question