在这种情况下,自然是遵循"Robust Error Handling and Cleanup in ObjectScript "中的模式,使用 try/catch/pseudo-finally 或注册对象来管理析构函数中的清理工作。%Stream.File*也有一个 "RemoveOnClose "属性,您可以对其进行设置,但要小心使用,因为您可能会不小心删除一个重要文件,而且这个标志会在调用%Save()时被重置,因此您需要在重置后将其设回 1。
不过,有一个棘手的情况——假设你需要临时文件在外部堆栈级别中继续存在。例如:
ClassMethod MethodA()
{
Do..MethodB(.filename)
// Do something else with the filename
}
ClassMethod MethodB(Output filename)
{
// Create a temp file and set filename to the file's nameSet filename = ##class(%Library.File).TempFilename()
//... and probably do some other stuff
}
ClassMethod MethodA()
{
Set tempFileManager = ##class(%IPM.Utils.TempFileManager).%Get()
Do..MethodB(.filename)
// Do something else with the filename// The temp file is cleaned up automatically when tempFileManager goes out of scope
}
ClassMethod MethodB(Output filename)
{
Set tempFileManager = ##class(%IPM.Utils.TempFileManager).%Get()
// Create a temp file and set filename to the file's nameSet filename = tempFileManager.GetTempFileName(".md")
//... and probably do some other stuff
}
Our Plumbing Services in Dubai provide expert, fast, and affordable solutions for residential and commercial plumbing needs. Whether you are dealing with a leaking pipe, blocked drain, faulty water heater, or require complete plumbing installation, our skilled plumbers deliver efficient and long-lasting results.
We use advanced tools, high-quality materials, and industry-approved techniques to diagnose and resolve plumbing issues safely and effectively. Each service begins with a detailed inspection to identify the root cause and prevent future problems.
Our plumbing services in Dubai include leak detection and repair, blocked drain cleaning, pipe repair and replacement, tap and mixer installation, toilet repair, water heater installation and maintenance, bathroom and kitchen plumbing, and emergency plumbing services.