Hi, In ASP.NET web application a worker thread creates a non-threadpool thread like below:
private static bool _refreshInProcess = false; public delegate void Refresher(); private static Thread _refresher; private static void CreateAndStartRefreshThread(Refresher refresh) { _refresher = new Thread(new ThreadStart(refresh)); _refresher.Start(); } private static void Refresh() { LoadAllSystemData(); } static public void CheckStatus() { DateTime timeStamp = DateTime.Now; TimeSpan span = timeStamp.Subtract(_cacheTimeStamp); if (span.Hours >= 24) { if (Monitor.TryEnter(_cacheLock)) { try { if (!_refreshInProcess) { _refreshInProcess = true; CreateAndStartRefreshThread(Refresh); } } finally { Monitor.Exit(_cacheLock); } } } } static public void LoadAllSystemData() { try { if (!Database.Connected) { if (!OpenDatabase()) throw new Exception("Unable to (re)connect to database"); } SystemData newData = new SystemData(); LoadTables(ref newData); LoadClasses(ref newData); LoadAllSysDescrs(ref newData); _allData = newData; _cacheTimeStamp = DateTime.Now; // only place where timestamp is updtd } finally { _refreshInProcess = false; } }
and LoadAllSystemData is also called elsewhere from same lock-guarded section as CheckStatus. Both calls are in their try-bolcks that also have catch-block.
Now my questions are 1. If LoadAllSystemData throws an exception, when it's called from non-threadpool thread in method Refresh, what will happen? Nobody can catch it.
What happens when it's done 1000 times? Are these exceptions stored somewhere and thus stress the system and ultimately crash it due memory exhaustion or something?
Is there good solution to catch them without waiting in the creating threadpool thread for the created thread to finish?
Thanks a lot! -Matti