x++ - setTimeOut 和本地函数

标签 x++ axapta

我正在开发 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/

相关文章:

axapta - 找不到定义的变量

axapta - ax中的FormControl和FormBuildControl有什么区别

.net - 在 AX 2009 中使用嵌套 .NET 枚举

axapta - setTmpData() 在动态添加的表单 DataSource 上

x++ - 在动态 ax 中读取逗号分隔值 (csv) 文件

axapta - 拦截 AX 2012 中的 doInsert、doUpdate 和 doDelete

sql-server - 启动 AX 2012 R3 服务时出错

axapta - 表更新事件处理程序

axapta - 查询范围不等于0

runtime-error - Axe 2012 tts 错误