I have a Page_Load event which invokes a big task which can be memory hungry. I have been having "Out Of Memory" exceptions. So I have decided to put in a MemortFailPoint which will create "Insufficient Memory" Exceptions thus preventing the Web App from collapsing. However the memory problem is likely to be temporary since the Garbage Collector is going around all the time and releasing memory. So I want to re enter the relevant code after a period of time after the exception has been raised to try again. I guess I would try say five times and then stop. The question is what is the best way of coding this.
My Page load code may start to look the attached. I could do with some help on fleshing out the code please.
P.S I have profiled the memory usuage and leakage does not looks to be a big problem. However I think I might be suffering from a variable loads on a share host and variable concurrent loads on my app hence the need to put in this self protection code.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MFP As MemoryFailPoint
MFP = New MemoryFailPoint(35) ' Check that 35MB available otherwise raise InsufficientMemoryException exception
'Run Big task
Catch ex As InsufficientMemoryException
' Exit if 3 attempt
' Some sort of timer for 10 secs
' Re Enter Big Task