有时候某些函数在执行时可能会遇到数据一些问题,导致可能超出预期的时间,这时候可能并不是我们想要的数据,我们可以把这样的数据揪出来。
C#已经封装了一些好用的函数,下面放上一段代码片段。
类库Task.Factory自带的类方法实现
List<Geometry> geometrydata = null;
bool timeout = true;
float btime = Time.realtimeSinceStartup;
Task.Factory.StartNew(() =>
{
geometrydata = VectorUtils.TessellateScene(sceneInfo.Scene, tessOptions, sceneInfo.NodeOpacity);
timeout = false;
}).Wait(10*1000);
Debug.Log("SceneNode "+i+"用时:"+ (Time.realtimeSinceStartup-btime));
if (timeout)
{
#if UNITY_EDITOR
Debug.LogError(hinfo.headName + "SVG文件存在错误,无法按时读取.");
#endif
SvgTest.inst.BadOut("SVG文件存在错误,无法按时读取.:" + svgHead.svgName + " - " + hinfo.headName);
continue;
}