setTimeOut和本地函数 [英] setTimeOut and local function
问题描述
我正在使用Ax 4.0
I'm working on Ax 4.0
我试图在具有局部功能的作业中使用Object.setTimeOut方法,如
I'm trying to use the Object.setTimeOut method in a job with a local function, as stated in the 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);
}
但是这个简单的工作不会产生任何结果,因此看来我在这里缺少了一些东西.
But this simple job doesn't produce anything, so it seems I'm missing something here.
有人为此工作吗?
推荐答案
setTimeout
方法不适用于作业中的本地功能.
The setTimeout
method does not work with a local function in a job.
有关工作示例,请查看表单tutorial_Timer
.
For a working example have a look on the form tutorial_Timer
instead.
更新:
setTimeout
方法是一个魔术"函数,但是不会将AX变成多线程环境.
The setTimeout
method is a "magic" function, but it does not turn AX into a multithreading environment.
它仅在Windows 事件循环起作用时起作用.在AX上下文中,这意味着表单正在运行,而其他人正在等待表单完成. sleep
函数不符合条件.
It only works while a Windows event loop is in action. In the AX context it means that a form is running and someone else is waiting for the form to complete. The sleep
function does not meet the criteria.
该对象还必须是活动的",调用垃圾回收对象是不好的!
Also the object must be "alive", calling a garbage collected object is no good!
示例(基于类):
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());
}
这篇关于setTimeOut和本地函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!