I solved the crash issue by adding all R code to the new thread. It runs perfectly. In debug mode I can even see that the R code is evaluated correctly! Code below (it is in VB but easy to covert to C#). Plus I included some more context that may help.
The catch is, now that we are in another thread, I cannot access the UI thread. Seems there's a great way to accomplish this in Win Forms using a UI's Invoke method but webcontrols don't seem to have this method. Hope this helps some.
Public Class SPF_R
Inherits System.Web.UI.Page
Dim t As System.Threading.Thread
...
Private Sub RunRStuff()
Dim RCode As String = ""
Dim engine As REngine = REngine.GetInstance(Nothing, True, Nothing)
Dim myPath As String = ViewState("Folder") & ViewState("File")
engine.Initialize()
engine.Evaluate("library(MASS)") : RCode &= "library(MASS)" & vbCrLf
engine.Evaluate("library(ggplot2)") : RCode &= "library(ggplot)" & vbCrLf
engine.Evaluate("library(broom)") : RCode &= "library(broom)" & vbCrLf
...
End Sub
Private Function DevelopSPF() As Boolean
cmdSPF.Enabled = False
t = New System.Threading.Thread(AddressOf RunRStuff, 2500000)
t.Start()
cmdSPF.Enabled = True
Return True
End Function
...