Batch processing files - rhino crashes when shading all views

Dear Everyone
i m writting a batch processing of nearly 1000 files - using RhinoCommon. For opening the next file i use a scripted Version of the “-_open” command. Same for saving.“-_SaveAs …”

string script = String.Format("-_SaveAs....\"{0}\" _Enter", pathSaveAs); 
RhinoApp.RunScript(script, false);

See

to obtain a reference to the new doc i use
Rhino.RhinoDoc.ActiveDoc

Now Rhino crashes after 25 to 40 files, Visual Studio Debugger is not Breaking or catching anything.
The problem signature varies.
The Memory-usage by Rhino is constant around 200 MB.

Any help is welcome.

Thanks

best Tom

windows-crash-Info

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	Rhino.exe
  Application Version:	5.12.50810.13095
  Application Timestamp:	55c9196b
  Fault Module Name:	mfc100u.dll
  Fault Module Version:	10.0.40219.1
  Fault Module Timestamp:	4d5f1436
  Exception Code:	c000041d
  Exception Offset:	000000000026c447
  OS Version:	6.1.7601.2.1.0.256.48
  Locale ID:	2055
  Additional Information 1:	aa45
  Additional Information 2:	aa45bd452f727794a7b21067a5029d05
  Additional Information 3:	f1cb
  Additional Information 4:	f1cb827c1d19930486af05fd3540fe79


Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	Rhino.exe
  Application Version:	5.12.50810.13095
  Application Timestamp:	55c9196b
  Fault Module Name:	opennurbsx64.dll
  Fault Module Version:	5.12.50810.13095
  Fault Module Timestamp:	55c915fb
  Exception Code:	c000041d
  Exception Offset:	00000000002e0028
  OS Version:	6.1.7601.2.1.0.256.48
  Locale ID:	2055
  Additional Information 1:	0260
  Additional Information 2:	0260fc2ced92754f6c990b3e7e18f355
  Additional Information 3:	993d
  Additional Information 4:	993d4332e629cbc4a6aec0368f9a5b4e

ok i managed to find the function that courses the error

	static public void ShadeAllViews(RhinoDoc doc)
    {
        DisplayModeDescription[] shade_arr = null;
        try
        {
            DisplayModeDescription[] allModes = DisplayModeDescription.GetDisplayModes();
            shade_arr = allModes.Where<DisplayModeDescription>(v => v.EnglishName == "Shaded").ToArray();//<DisplayModeDescription>;
        }
        catch
        {
            RhinoApp.WriteLine("Displaymode shaded not found");
        }

        if (shade_arr != null && shade_arr.Length == 1)
        {
            foreach (RhinoView view in doc.Views)
            {
                view.ActiveViewport.DisplayMode = shade_arr[0];
            }
        }
    }

and therefor this disappointing solution solve somehow what i need:

    static public void ShadeAllViewsWithScript()
    {
        RhinoApp.RunScript(@"-_SetDisplayMode _Viewport=_All _Mode=_Shaded ",true);
    }

I’m curious if this works (too):

static void ShadedDisplayMode(RhinoDoc doc, bool bRedraw)
{
  if (null != doc)
  {
    var shaded_id = new System.Guid("8BC8DEBE-C83B-4c47-B13C-9DB074510CAC"); // fixed uuid
    var display_mode = DisplayModeDescription.GetDisplayMode(shaded_id);
    if (null != display_mode)
    {
      var view_list = doc.Views.GetStandardRhinoViews();
      foreach (var view in view_list)
        view.ActiveViewport.DisplayMode = display_mode;

      if (bRedraw)
        doc.Views.Redraw();
    }
  }
}

– Dale

@dale
Yes. thanks Dale. it works with your approach.
but in terms of learning - any feedback about the error in my approach would be great.
even if it is a quess.

THANKS