One way, i fixed the problem temporary for the crashing is by calling the below code right after the renderWindow#Close method.
MethodInfo shutDown = typeof(Microsoft.Win32.SystemEvents).GetMethod("Shutdown", BindingFlags.NonPublic | BindingFlags.Static,
(Binder)null, new Type[] { }, new ParameterModifier[] { });
shutDown.Invoke(null, new object[] { });
Process.GetCurrentProcess().Kill();