Looking at what happens when a C # / ASP.NET thread completes and how to work around problems

I am working on an ASP.NET site that, upon some requests, will launch a very lengthy caching process. I am wondering what exactly happens if the execution timeout is reached while it still works in terms of how the code handles it.

In particular, I'm curious about things such as if the code in the attempt to try / finally block is finally still running?

Also, I'm not sure if I want caching to stop even if it takes so long, is there a way to create new threads, etc., so that I can bypass this execution timeout? I think it would be much nicer to immediately return to the user and say that "the cache is being collected", and not just give them a timeout. I recently started playing with some lock code to make sure that only one cache build occurs at a time, but I am thinking of expanding this so that it does not go out of sync.

I really did not play with creating threads like me, so I'm not sure exactly how they work, especially in terms of interacting with ASP.NET. for example, if the born thread that launched it is terminated, will this affect the spawned thread?

I know that there are many different questions here, and I can separate them if this is considered the best, but they all seem to go together ... I will try to summarize the questions, though:

  • Will the final block still be executed if the thread terminates in ASP.NET and in the try block
  • Will newly created threads obey the same timeouts as the original thread?
  • Should newly created threads die at the same time as the parent thread that created them?
  • And a general one of what is the best way to execute long background processes on an ASP.NET site?

Sorry for some noobish questions, I have never played with threads and they still scare me a bit (my brain says they are difficult). I could probably check the answer to many questions, but I would not be sure of my tests. :)

Edit to add:

In response to Capital G:

, ASp.NET , , . , , , (, , , , , , ).

ASP.NET - , , , , ASP.NET, , .

, ( , 100% ), , , , , .

BackgroundWorker -, ( ASP.NET). , "-", , ... , , .:)

+3
2
  • , finally, , . .., .

  • , , . , , , , , . , . , .

  • , , , , - , , - /. .

  • ASP.NET, -, 10-20s , , , ASP.NET . , , , ( 10-20 +), , , .

, , 30-60 +, ASP.NET - , Windows - , .

: Threading CAN , , , , , , , , , , , , , , BackgroundWorker, .. ( , , ).

http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

+1

, -; ASP.NET; ; .. . , , . . . , . , . .

, , - . , , , . .

+1

Source: https://habr.com/ru/post/1760042/


All Articles