Last post Sep 20, 2017 05:24 PM by PatriceSc
Sep 20, 2017 08:09 AM|Alex9|LINK
How can I tell Windows that my thread is long running?
Thank you for assistance.
Sep 20, 2017 09:35 AM|PatriceSc|LINK
In ASP.NET ? I wouldn't recommend that. This is just not the purpose of a web application. What is the use case?
You have tons of approach going from https://www.codeproject.com/Articles/39118/Keep-Your-Website-Alive-Don-t-Let-IIS-Recycle-Your to
https://www.mikesdotnetting.com/article/254/scheduled-tasks-in-asp-net-with-quartz-net depending on your need.
You may want to consider also simplest option if running this as part of your web site is not already your last resort (Windows scheduled jobs, SQL Server jobs, or even a separate server etc...)
Sep 20, 2017 09:42 AM|Alex9|LINK
And what about webapi? Why not recommend?
Sep 20, 2017 10:00 AM|PatriceSc|LINK
It could. We would need to understand first your scenario.
If looking at real world api usage for heavy work (media transcoding for example) you'll likely see that the work is not done immediately. You just queue a request and get a job id so that you can query for the work status at a later time.
The work itself is done behind the scene rather than during your http request (and likely on another machine than on the web server).
Edit : for example
The application just provides input files, queue a task, monitor a task and get the output file when done. The bulk of the work is offloaded to other machines.
Knowing which kind of work you have, at which scale, if your "long running" thread is expected to take few minutes or hours might help.
Sep 20, 2017 10:39 AM|Alex9|LINK
Is it right that I can run waiting infinite loop thread in a static variable on core mvc site which can talk with other web api on each incoming http request? What is the purpose of web application?
Sep 20, 2017 11:39 AM|PatriceSc|LINK
It seems already how a web server works. This is basically a loop that waits for incoming http requests to process them. For example in much earlier "self hosting" implementation you would call https://msdn.microsoft.com/en-us/library/system.net.httplistener.getcontext(v=vs.110).aspx in
a loop to process incoming requests (WARNING: this is outdated).
We would need really some context? First do you have some heavy work to launch from your web site or do you try just to understand how a web server works ?
BTW if using ASP.NET Core you have a dedicated forum.
Sep 20, 2017 04:35 PM|Alex9|LINK
Now, I have read exam ref 70-483 and I've got many questionas while reading it. In this book I see phrase: "you can tell Windows that your thread is long running".
Sep 20, 2017 05:24 PM|PatriceSc|LINK
Ah ok, I thought it was from an ASP.NET perspective rather than just from a C# language perspective.
A search just gives me
For this kind of question I usually start at the low level Windows API documentation (as the .NET usually expose parts of this) but failed to find anything. I'm not sure about that but for now I would say that a "long running thread" is just a standalone
thread rather than one taken from a threadpool.
For general C# question https://forums.asp.net/37.aspx/1?C+ might be a better place.