Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Is creating a timer/separate thread within an ASP .Net MVC Web application a bad thing to do?

Posted on 2014-04-11
6
Medium Priority
?
1,573 Views
Last Modified: 2014-04-17
Hi:

We have an ASP .Net MVC web application.

In order to do some processing on set intervals, I'm looking at the possibility
of creating a timer or a thread within the app (server side)  to do the clean up.

Is this a good design practice (Am I breaking some kind of rules here)?
What are the possible short comings of such an approach?

Thanks,
JohnB
0
Comment
Question by:jxbma
[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
  • 3
  • 2
6 Comments
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 39995322
Its fine to create a separate worker thread. There are two things to keep in mind (in my opinion). The first is that it the website isn't accessed for a period of time, the application shuts down, shutting down your worker thread. The second is to make sure it doesn't slow down the start up of the site itself, or slow down the site while its running. Other than that go for it.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39995351
@dale_burrel

There are two things to keep in mind (in my opinion). The first is that it the website isn't accessed for a period of time, the application shuts down, shutting down your worker thread.
Is that true if the thread has its IsBackground property set to false?

@jxbma

So long as you aren't expecting the separate thread to return data to the user, then it should be fine--so long as you don't consume all of your resources, like any thread usage should be concerned with. If you do need to return data to the user, then you would need a different (or perhaps modified) approach.
0
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 39995360
@kaufmed I believe so, quoting your link "Once all foreground threads belonging to a process have terminated, the common language runtime ends the process. Any remaining background threads are stopped and do not complete."
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 1

Author Comment

by:jxbma
ID: 39999146
What about when this MVC application gets scaled out across a server farm?
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1000 total points
ID: 39999228
The only issues that I am aware of when you start talking about farms is regarding session handling. My experience with farms is limited, though.
0
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 1000 total points
ID: 40003255
The thread you create will only run within one of the processes on one of the servers handling your site - unless you specifically write your code to run it on all of them.

In fact you will need to be very specific in how to write your code, because you will probably either only want one instance of it running or an instance in every process. Either way will add some complexity, because normally one would use a mutex to ensure you only get a single instance, but that won't work across multiplse servers.

And regardless of how many servers are handling requests to your site, if they all shut down due to inactivity your process stops. If you only have one instance and that process shuts down your process stops.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 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