web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Global cache in thread.

(0) ShareShare
ReportReport
Posted on by

Hello, I am using thread as example on tutorial_Thread.

Everything work fine, but I want to pass objects between thread.

I see that Thread.setParam get as input a container.

I want to pass an object (the 'element' property of current form).

I see that container cannot include in its list of parameters an object (i.e, I cannot pass ['str', myObject]),

so I want to use the global cache.

When I setting global cache parameter, and get it on the thread method, It is null (that not happens for non-thread methods).

How can I pass global cache variable, and get it in thread (such as on  TutorialThread::runThread method).

The global cache code may look like :

     SysGlobalCache globalCache;
    ;
    super();
    globalCache = Appl.globalCache();
    globalCache.set("listviewsql", curuserid(), element);


and on thread function (such as TutorialThread::runthread):

     SysGlobalCache globalCache;
    object c;
    ;
    super();
    globalCache = Appl.globalCache();
    c = globalCache.get("listviewsql", curuserid(), element);
// c is null!!! Why?

Thanks :)

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,972 Most Valuable Professional on at

    It sounds like a lot of effort to create a thread-unsafe program. Are you sure it's a good idea from the beginning? What are you trying to achieve?

  • Community Member Profile Picture
    on at

    Just need to pass parameters from one to a thread class.

    One is the query, and the other one is a listview object, that I fill.

    The thread class may doing query - just for view, but if it take too long, so I need to stop it in the middle.

    I cannot pass a listview object, but I can pass a form::element object.

    When using a thread, I cannot see the ele

    (There are some cases, I need to stop the query in middle).

    Thanks :)

  • Community Member Profile Picture
    on at

    If not thread - is there any other way stopping long time consuming method in middle?

  • Martin Dráb Profile Picture
    237,972 Most Valuable Professional on at

    If I needed such behavior, I would probably implement it in .NET, because it's already supported there. See Cancel Async Tasks after a Period of Time, for example. Whether it's applicable in your case depends on what you're doing, which is unknown to me.

  • Community Member Profile Picture
    on at

    Just want to do: select (direct sql select) fill a listbox, and be able to stop it, whether it is a long query.

    Thanks :)

  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    You will not be able to change a UI element in an off-UI thread.  You cannot interact with a form at all off-UI thread.  The only way to achieve this is to use callbacks to the UI thread using Thread::executeInUIThread(..).  I once did an off-thread process (sending a fax) that produced a progress bar and rendered errors in the infolog.  All calls to the SysProgress and to the infolog had to be sent back to the UI thread to work.

    As far as sending objects, anything that you can serialize (pack and unpack) works fine.  Records, for example, can be packed using built-in methods in AX 2012.

  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    I should have been more specific.  You'll have to pack and unpack objects yourself, but that gets the job done.

  • Verified answer
    Community Member Profile Picture
    on at

    Solved.

    I did Thread::executeInUIThread ... that's how I refer to non-thread from thread.

    in the execute method I can refer to globalcache, or whatever.

    Thanks :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans