我正在开发 Axe 4.0
我正在尝试在具有本地函数的作业中使用 Object.setTimeOut 方法,如 msdn documentation : 中所述。
static void setTimeOutJob()
{
Object o = new Object();
void printText()
{
;
info( "2 seconds has elapsed since the user did anything" );
}
;
// Set a Time Out with the idle flag set to false
o.setTimeOut(identifierstr(printText), 2000, false);
}
但是这个简单的工作不会产生任何结果,所以我似乎在这里遗漏了一些东西。
有人用过这个吗?
最佳答案
setTimeout
方法不适用于作业中的本地函数。
有关工作示例,请查看 tutorial_Timer
表单。
更新:
setTimeout
方法是一个“神奇”函数,但它不会将 AX 转变为多线程环境。
它仅在 Windows event loop 时有效正在行动。在 AX 上下文中,这意味着表单正在运行,而其他人正在等待表单完成。 sleep
函数不符合条件。
此外,该对象必须是“事件的”,调用垃圾回收对象是没有好处的!
示例(基于类):
class SetTimeoutTest extends Object //Yes, extend or it will not compile
{
str test;
}
public void new()
{
super();
test = "Hello";
}
public str test()
{
return test;
}
protected void timedOut()
{;
test = "2 seconds has elapsed since the user did anything";
info(test);
}
static void main(Args args)
{
SetTimeoutTest t = new SetTimeoutTest();
FormRun fr;
;
t.setTimeOut(methodStr(SetTimeoutTest,timedOut), 2000, false);
//sleep(4000); //Does not work
fr = ClassFactory::formRunClassOnClient(new Args(formstr(CustGroup))); //Could be any form
fr.init();
fr.run();
fr.wait(); //Otherwise the t object runs out of scope
info(t.test());
}
关于x++ - setTimeOut 和本地函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11359271/