A ASP.NET Web application creates a non-threaded thread like a thread below:
Private static bool _refreshInProcess = false; Public representative zero refresher (); Private Stable Thread _ Refresher; Private Static Zero CreateAndStartRefreshThread (Refresh Refresh) {_refresher = New Thread (New Thread Start (Refresh)); _refresher.Start (); } Private Static Zero Refresh () {LoadAllSystemData (); } Fixed Public Zero CheckStatus () {DateTime timeStamp = DateTime.Now; Time Span = Timestamp. Subtract (_cacheTimeStamp); If (span.Hours> = 24) {if (Monitor.TryEnter (_cacheLock)) {try {if (! _refreshInProcess) {_refreshInProcess = true; CreateAndStartRefreshThread (fresh); }} Finally {Monitor. Extras (_cacheLock); }}}} Fixed Public Nine LoadAllSystemData () {try (if !! Database.Connected) {if (! OpenDatabase ()) new exception throw ("(Unable to connect to database)"); } SystemData newData = new system data (); Load Tables (Refund Data); Load Classes (Refund Data); Loaded Soldiers (Refused Data); _allData = newData; _cacheTimeStamp = DateTime.Now; // is the only place where the timestamp updtd} finally {_refreshInProcess = false; }}
and LoadAllSystemData are also called as a single lock-protected section anywhere in the form of checkstats. Both calls are in their efforts - those who have hold-blocks too.
Now my question is 1. Load load system system throws an exception, what happens when the method is called in a refresh with a non-threaded thread? No one can catch it
-
What happens when it is done 1000 times? Are these exceptions stored somewhere else and thus there is pressure on this system and eventually it causes memory exhaustion or something to crash?
-
Is there a good solution for them to wait without making thread thread threads to eliminate the thread?
Thanks a lot!
- If the exception is raised in the non-threadpulge thread in the background and in the end it Not controlled by any cache block, it is promoted as long as it does not reach the beginning of the stack. Then the thread eliminates its execution - the exception is not stored anywhere, then the thread has been dropped in the context of its exception.
- Exception is expensive in NAT, so if you guess that 1000 times this happens, maybe this is not an exception, but there is only one part of your application flow and you should not take exception.
- If you want to catch exceptions from background activity, as an alternative you can use the BeginInvoke / EndInvoke methods of the representative. If there is no exception in the background operation, then it will be given in the end-inkok call.
No comments:
Post a Comment