How to make `CALLBACK` function across threads?

It seems when I set up a callback in Global Embeds > Program Setup the callback only triggers for the main thread, when a window is opened with START the callback won’t trigger in that thread unless I add another call to CALLBACK - is there a way to set the callback once and have it run regardless the thread it’s on?

Is the DCT file set to threaded?

ABFile.inc

FileManager                   CLASS,IMPLEMENTS(FileCallBackInterface),TYPE,MODULE('ABFILE.CLW'),LINK('ABFILE.CLW',_ABCLinkMode_),DLL(_ABCDllMode_)

FileCB.inc

FileCallBackInterface INTERFACE
FunctionCalled PROCEDURE(SIGNED opCode, *Params Parameters, *CSTRING FileErrCode, *CSTRING FileErrMsg), BYTE
FunctionDone   PROCEDURE(SIGNED opCode, *Params Parameters, *CSTRING FileErrCode, *CSTRING FileErrMsg), BYTE
                      END

I don’t know anything about that thing you’re using, but if you are using a class, you could IMPLEMENT Capesoft GUTS Interface. Then you can communicate to any other objects that also implement the GUTS interface. May or may not be what you’re looking for, but it is free, thread independent, and relatively easy to use once it’s set up.

Check out the stuff about “Family”. I think that’s what you need. CapeSoft GUTS Complete Documentation

https://www.capesoft.com/accessories/gutssp.htm

The application is still Legacy Clarion, so no ABC - but File does not have the THREAD attribute - it’s a TOPSPEED file if that matters

Did it by creating a *Manager class, which has the THREAD attribute and in it’s CONSTRUCT sets the callbacks (DESTRUCT removes them) - this way, on each thread a new instance is created and the callbacks are added again.

Borrowed the idea from: Thread termination monitoring / was: Passing procedure as a parameter prior to 11.1 - #4 by MarkGoldberg

It makes sense to me that the CallBack(File) monitoring must be “enabled” for each Thread .. when the File is THREAD. Having it always get posts from every Thread that opens and handle them seems it could be difficult.

It you look at the ABC FileManager Class it the Implements(FileCallBackInterface). If the File is THREAD then the Class is THREAD so the CallBack is a new instance limited to one Thread. For a Non-Thread file there is one Non-Thread FM so it must get call backs from all Threads

If you have any Non-Thread files you should check how it works. You would Not want it removed in the Destruct.

research in the help NOTIFICATION - also as it shows how to use an address of an interface to pass to another thread.. this lets you do anything you like and you dont have the problems of cross thread interface calling in CPP.. clarion wraps the whole thing up with the Instance command, really the designers of clarion just made it all pretty simple and it a very very nice paradigm that really should be mutliplatform and 64 bit and Clarion might have had a much bigger audience.. really very nicely done..we have used this for training AI on a slight more complex example using ticketed objects with the address passed on the notification. This little gem in the help is the key to creating some pretty fancy stuff. Well done topspeed.

Example:

NOTIFICATION  - Multi Thread Transfers - cross thread call backs via a posted messages 

CASE EVENT()
OF EVENT:Accepted
CASE ACCEPTED()
OF ?Start
START (T1)

OF ?Load
CALL ('DLL.DLL', 'EntryPoint', 1)
ELSE
Q.Feq = ACCEPTED()

GET (Q, Q.Feq)
IF ERRORCODE() = 0 AND Q.Op <> 0
DM &= Q.ID + 0
DM.ExecuteMenu (Q.Op)

END
END

OF EVENT:Notify

IF NOTIFICATION (NCode,, NParam) !NOTIFY has sent a Notify Event. Get Code and Parameter

DM &= NParam + 0 !Assign passed parameter to reference var

CASE Ncode !Test the Notify Code
OF NOTIFY:Load

DM.CreateMenu (Q) !Execute appropriate action

OF NOTIFY:Unload
DO DestroyMenu
UNLOAD ('DLL.DLL') !Execute appropriate action

END
END
END

This is almost certainly a bug waiting to happen in your program. The use case for a FILE not to have ,THREAD is really narrow.

You should review your decision to have threading off for the file. Or reassure us by indicating that all access to the file is controlled by a CriticalSection etc.

Seems my edit didn’t go through yesterday (seemed the forum had an outage for a few minutes, at least for me as it didn’t load) - but I corrected my statement, the files are THREAD = but Copy Details doesn’t show this (I didn’t open de Dictionary itself, later I did and saw it contained the THREAD)

That one was on me. There was a new version of discourse available and I tried to install but it broke the hub, so I had to revert to the currently installed version. Sorry you lost your edit.

Mark