ReloadResource()
Updated: 9 Dec 2024
Updated: 9 Dec 2024
Reloads a Notch resource. Can be used in conjunction with GetFileModifiedDate() to automatically reload a resource when it changes on disk. See the second example below.
On Windows, the modified date of a resource can update before the file is fully written to disk. This may lead to reading incomplete or incorrect data from the resource. To address this issue, introducing a brief delay before reloading the resource ensures the file on disk is fully written and valid. See the sleep() function below.
bool ReloadResource();
function Update()
{
myResource = Document.FindResourceByName("myFile.csv");
if(myResource != null)
{
objRes.ReloadResource();
}
}
This example automatically reloads a resource that has changed on disk:
LastModifiedTime = 0;
function sleep(milliseconds)
{
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++)
{
if ((new Date().getTime() - start) > milliseconds)
break;
}
}
function Update()
{
newModifiedTime = GetFileModifiedDate("c:\\myFolder\\myFile.csv");
if(newModifiedTime != null)
{
if(newModifiedTime > LastModifiedTime)
{
myResource = Document.FindResourceByName("myFile.csv");
if(myResource != null)
{
//sleep(10)
myResource.ReloadResource();
LastModifiedTime = newModifiedTime;
}
}
}
}