Page 1 of 1

Is there a function that allows you to find out the names of the functions running for execution?

Posted: Sun Nov 27, 2022 6:43 am
by Eugene Lutsenko
Is there a function that allows you to find out the names of the functions running for execution?

Is there a function that allows you to find out the names of the functions running for execution? I have such a problem in my system. When you do everything properly, everything works fine. But when you run the wrong function for execution, it can give an error. Before starting the function, I would check whether the functions that are allowed are already running. And if some others are running, then the function would not be executed. Then there would be fewer such mistakes. In general, the problem is that the system often issues errors restoring the environment after multiple launches of various modes. I don't know how to cope with these, how to solve this problem

Re: Is there a function that allows you to find out the names of the functions running for execution?

Posted: Mon Nov 28, 2022 5:40 am
by jdsoft
Hello Eugene
No, there is not.
Below some code you can try.

Code: Select all

CLASS IsFunctionRunning
CLASS VAR aFunctions 
CLASS METHOD InitClass 
CLASS METHOD IsRunning
CLASS METHOD StartFunction
CLASS METHOD StopFunction
ENDCLASS 

CLASS METHOD IsFunctionRunning:InitClass()
::aFunctions               := {}
Return 

SYNC CLASS METHOD IsFunctionRunning:IsRunning(cFunction)
Return Ascan(::aFunctions,{|a|a[1] == cFunction) > 0 

SYNC CLASS METHOD IsFunctionRunning:StartFunction(cFunction)
LOCAL lStartOk             := .F. 
If !::IsRunning(cFunction)
   Aadd(::aFunctions,{cFunction,ThreadId()})
   lStartOk                := .T.
Endif    
Return lStartOk 

SYNC CLASS METHOD IsFunctionRunning:StopFunction(cFunction)
LOCAL lStopOk              := .F. 
LOCAL nPos                 := Ascan(::aFunctions,{|a|a[1] == cFunction)
If nPos > 0 .and. ::aFunctions[nPos,2] = ThreadId()
   Aremove(::aFunctions,nPos] 
   lStopOk                 := .T. 
Endif    
Return lStopOk 


Function MyFunction()
If IsFunctionRunning():StartFunction("MyFunction") 
   //
   // This is the only run  
   //
   Your code here 
   //
   // We are done 
   //
   IsFunctionRunning():StopFunction("MyFunction") 
Else 
   MsgBox("Function already running")
Endif
Return    


Re: Is there a function that allows you to find out the names of the functions running for execution?

Posted: Mon Nov 28, 2022 6:55 am
by Eugene Lutsenko
Thank you, Jack! I will definitely try