Page 1 of 1

Forced closing function

Posted: Sun Dec 08, 2013 8:33 pm
by Eugene Lutsenko
Is there a way to Alaska to forcibly close a specific function previously running with the command from another function?

Re: Forced closing function

Posted: Mon Dec 09, 2013 2:01 am
by Tom

Code: Select all

Function Function1()
DO WHILE RunThisFunc()
  * Code
ENDDO
RETURN NIL

FUNCTION RunThisFunc(lSetRun)
STATIC RunIt := .T.
IF PCount()=1
  RunIt := lSetRun
ENDIF
RETURN RunIt
Any other func/proc can terminate Function1 now by calling RunThisFunc(.F.).

Re: Forced closing function

Posted: Mon Dec 09, 2013 12:50 pm
by Eugene Lutsenko
Thank you, Tom! That's understandable. But I had something else in mind. Let's say somewhere in the program I ran a function whose name he brought in when you start the database, and at the completion of the function is the name of the database is deleted. And elsewhere in the program looked at the database, I saw that at the moment the function is executed with the same name, and forcibly interrupted her performance, and then removed her name from the database. In this case the function of demand itself can have any form, for example it may be the screen form with the dialogue process and generally anything. In other words the software to do what we can do manually in Task Manager when forcibly stop the program, but the program and function. Thus it is desirable to open all database function interrupted closed at the termination of its operation.

Re: Forced closing function

Posted: Mon Dec 09, 2013 1:29 pm
by Auge_Ohr
Eugene Lutsenko wrote:In other words the software to do what we can do manually in Task Manager when forcibly stop the program, but the program and function.
you just can "kill a Task" ... but it does not say what will happens with your Data !
Eugene Lutsenko wrote:Thus it is desirable to open all database function interrupted closed at the termination of its operation.
CLOSE ALL will close all Database in one WorkSpaceArea.
If you use Threads that you have care of different WorkspaceArea.

Code: Select all

PROCEDURE AppExit()
   LOCAL bErrorHandler :=ErrorBlock( {|e| Break(e)} )
   LOCAL aWS, i
   /*
    * Absichern der shutdown-sequence vor rekursiven Fehlern
    * in DbCommit() udgl.
    */
    aWS := WorkSpaceList()
    FOR i:= 1 TO len(aWS)
        BEGIN SEQUENCE
          /*
           * Erzwinge das erfolgreiche Beenden aller
           * anstehenden Record updates im aktuellen
           * Workspace.
           */
           (aWS[i])->(DbCommit())
           (aWS[i])->(DbCloseArea())
        RECOVER

           (aWS[i])->(DbRRollback())
           (aWS[i])->(DbCloseArea())
        ENDSEQUENCE
    NEXT

    ErrorBlock( bErrorHandler )
RETURN

Re: Forced closing function

Posted: Mon Mar 03, 2014 9:19 pm
by Eugene Lutsenko
And as I can "kill task", ie close the previously executed function from another function. With these all will be fine, as I can before closing all databases

Re: Forced closing function

Posted: Mon Mar 03, 2014 10:08 pm
by Auge_Ohr
Eugene Lutsenko wrote:And as I can "kill task", ie close the previously executed function from another function. With these all will be fine, as I can before closing all databases
i say it again : if you do not "close" your Database before "kill Task" your Data will be corrupt !!!

to "kill a Task" you have to find its (Windows) Handle.
if you have the Title of a Window you can use FindWindowsA() API Function this Way

Code: Select all

Function KillWindow(cTitle)
LOCAL hWndDlg 

   hWndDlg := DllCall( "User32.dll", DLL_STDCALL, "FindWindowA", 0, cTitle )
   IF !( hWndDlg == 0 )
       SendMessageA( hWndDlg, WM_QUIT, 0, 0 )
   ENDIF
this work with Xbase++ Application if you have

Code: Select all

      nEvent := AppEvent ( @mp1, @mp2, @oXbp )
      DO CASE
         CASE nEvent == xbeP_Quit
              QUIT   // AppQuit()
         CASE ...
      OTHERWISE 
         oXbp:HandleEvent ( nEvent, mp1, mp2 ) 
      ENDCASE

Re: Forced closing function

Posted: Mon Mar 03, 2014 11:11 pm
by Eugene Lutsenko
I'll try to make the system mode, which closes all open windows