2012-07-06 63 views
2

我工作的AX 4.0setTimeout和局部功能

我想在工作中使用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); 
} 

陈述但是这个简单的工作不会产生任何东西,所以看起来我在这里错过了一些东西。

有人曾与此?

回答

3

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()); 
} 
+0

回答更新。 – 2012-07-10 15:27:37

+0

优秀的答案! – 2012-07-10 15:58:14

0

我只是不认为它与工作。我已经在元素级别的方法上使用过它,并且完成了element.setTimeout并且它工作正常。

+0

然后文档是误导。我已经在一个表单中使用了setTimeout,但是在这种情况下,在一个作业(仅用于测试目的)中将它用于本地函数会让事情变得更简单。现在我甚至无法在课堂上使用它。 – Pierre 2012-07-09 09:27:17

+0

我认为为了使setTimeOut工作,对象必须是“活着的”。 – 2012-07-09 15:05:51

+0

但我分享你的问题,它似乎并没有与一个班的工作! – 2012-07-09 15:27:44