?
Solved

How to control a thread

Posted on 2011-02-23
6
Medium Priority
?
372 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 332 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 334 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 8

Assisted Solution

by:Volox
Volox earned 334 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

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

801 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