我的代码在小型演示应用程序中运行良好,但是,当我在大型生产系统中运行它时,它会引发以下异常:
Unhandled Exception: System.ObjectDisposedException: Cannot access a closed Stream.
at System.IO.MemoryStream.get_Length()
at Gurock.SmartInspect.LogEntry.get_Size()
at Gurock.SmartInspect.SchedulerCommand.get_Size()
at Gurock.SmartInspect.SchedulerQueue.Remove(SchedulerQueueItem item)
at Gurock.SmartInspect.SchedulerQueue.Dequeue()
at Gurock.SmartInspect.Scheduler.Dequeue()
at Gurock.SmartInspect.Scheduler.Run()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
这是导致错误的 C# 代码:
// This grabs a bitmap from Mathematica. It works 95% of the time.
Bitmap bitmap = new Bitmap(Globals.State.Mathematica.EvaluateToImage(cmdGraph, 0, 0));
// Log to SmartInspect.
SiAuto.Main.LogBitmap("test", bitmap); // Errors disappear if this line is removed.