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 Microsoft Employee

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Global cache in thread.

    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 :)

  • Suggested answer
    Brandon Wiese Profile Picture
    Brandon Wiese 17,788 on at
    RE: Global cache in thread.

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

  • Suggested answer
    Brandon Wiese Profile Picture
    Brandon Wiese 17,788 on at
    RE: Global cache in thread.

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Global cache in thread.

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

    Thanks :)

  • Martin Dráb Profile Picture
    Martin Dráb 231,313 Most Valuable Professional on at
    RE: Global cache in thread.

    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
    Community Member Microsoft Employee on at
    RE: Global cache in thread.

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Global cache in thread.

    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 :)

  • Martin Dráb Profile Picture
    Martin Dráb 231,313 Most Valuable Professional on at
    RE: Global cache in thread.

    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?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,313 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans