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

  • Verified answer
    Community Member Profile Picture
    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
    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
    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
    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
    233,544 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
    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
    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
    233,544 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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans