Thanks again for your ideas Wessam.
Once in this state, UnlockRectangle calls return System.InvalidOperationException!
I will set a breakpoint and check the Write method next time the problem recurs.
One more strange thing I have noticed - the call stack in the error history for both the InvalidOperationException and the InvalidCallException show 2 sets of calls to the methods, but I don't see how this is possible (see below). The call stack in the debugger only shows 1 set of calls.
Any other ideas greatly appreciated...
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.DirectX.Direct3D.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>Kraz.vshost.exe</AppDomain><Exception><ExceptionType>System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Operation is not valid due to the current state of the object.</Message><StackTrace> at Microsoft.DirectX.Direct3D.Texture.UnlockRectangle(Int32 level)
at ICAN.IFC.GeoSpatialPlotter.GeoTerrainMesh.CreateTextureFromBitmapRegion(Device device, Texture texture, Rectangle rectBitmap, Bitmap bitmap) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\GeoTerrainMesh.cs:line 410
at ICAN.IFC.GeoSpatialPlotter.GeoTerrainMesh.UpdateTerrainTextureMap() in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\GeoTerrainMesh.cs:line 934
at ICAN.IFC.GeoSpatialPlotter.TerrainManager.UpdateTerrainLayerTexture(GeoTerrainMesh geoTerrainMesh, Boolean bForceUpdate) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\TerrianManager.cs:line 377
at ICAN.IFC.GeoSpatialPlotter.TerrainManager.GeoMeshLoadThread(Object plotterStateIn) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\TerrianManager.cs:line 474
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)</StackTrace><ExceptionString>System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Microsoft.DirectX.Direct3D.Texture.UnlockRectangle(Int32 level)
at ICAN.IFC.GeoSpatialPlotter.GeoTerrainMesh.CreateTextureFromBitmapRegion(Device device, Texture texture, Rectangle rectBitmap, Bitmap bitmap) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\GeoTerrainMesh.cs:line 410
at ICAN.IFC.GeoSpatialPlotter.GeoTerrainMesh.UpdateTerrainTextureMap() in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\GeoTerrainMesh.cs:line 934
at ICAN.IFC.GeoSpatialPlotter.TerrainManager.UpdateTerrainLayerTexture(GeoTerrainMesh geoTerrainMesh, Boolean bForceUpdate) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\TerrianManager.cs:line 377
at ICAN.IFC.GeoSpatialPlotter.TerrainManager.GeoMeshLoadThread(Object plotterStateIn) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\TerrianManager.cs:line 474
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)</ExceptionString></Exception></TraceRecord>