Solved

How to control a thread

Posted on 2011-02-23
6
362 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
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:tedbilly
tedbilly 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Form design in vb.net 7 20
Showdialog 8 21
What .NET website keeps me current? 9 32
install app on other machine 13 14
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now