Programmatically adding TIN to ArcMap: layer slowly disappears??

Discussion created by Sander77 on Dec 3, 2013
Hi everyone,

I'm programmatically adding a TIN from a file path to ArcMap 10.2.
It's something I've done so many times before and it has always worked. It also works now, but there seems to be a problem with the display. After the layer has been added to the TOC and I switch it on, it renders fine. However, after some (random) panning and zooming, the layer seems to gradually disappear, as if the cache is running dry or something.
ArcMap doesn't crash and the layers are still there somehow. If I click "Zoom To Layer" I actually zoom in to it (I can tell by the scrollbars and the scale indicator), but there's nothing to see.
If I save the MXD and reopen it, the layers are visible again.
Below is my code. Am I doing something wrong? Or did I run into a 10.2 render/caching bug?

ITin tin = new TinClass();
ITinLayer2 tinLayer = new TinLayerClass();
DirectoryInfo dirInfo = new DirectoryInfo(FullPathToMyTIN);
IWorkspace workspace = workspaceFactory.OpenFromFile(dirInfo.Parent.FullName, 0);
ITinWorkspace tinWorkspace = (ITinWorkspace)workspace;  // Explicit Cast

if (tinWorkspace.get_IsTin(dirInfo.Name))
 tin = tinWorkspace.OpenTin(dirInfo.Name);
if (tin == null || tin.IsEmpty)

tinLayer.Dataset = tin;
tinLayer.Visible = false;    // I don't want my layers to be visible by default, 
                                      since I'm adding multiple ones
tinLayer.Cached = false;  // The problem seemed to occur less frequently after adding 
                                      this line, but it still happens...
tinLayer.Name = "MyCustomName";

ArcMap.Document.FocusMap.AddLayer(tinLayer); // This works fine: no errors here
                                                            tinLayer, tinLayer.Dataset.Extent);

// I've also tried .PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null)
   or  .PartialRefresh(esriViewDrawPhase.esriViewGeography, null, tinLayer.Dataset.Extent)
   or  .Refresh(), but the problem remains

// I've also tried adding this, but the problem remains