This project is read-only.

how can close a thread

Topics: Attention VFPX Admins, General
Jun 30, 2011 at 1:26 PM

Dear all,

I´m using vfp2c32.fll library for creating a thread with function CreateThreadObject([ savedata.ABigData ], thisform, .t.)

It´s run ok, but sometimes I have to close the thread before it finish.

How can I do for stop and close the thread?

Best regards

Jul 5, 2011 at 8:13 PM

Hello,

DEFINE CLASS AsyncronousSQL AS Session OLEPUBLIC

   CallInfo = .NULL. 

   FUNCTION SendSQL(lcConnStr AS String, lcSql AS String) AS VOID

      DECLARE Sleep IN WIN32API INTEGER
      LOCAL lnCon, lnRet
      m.lnCon = SQLSTRINGCONNECT(m.lcConnStr)
      IF m.lnCon = -1
        && use AERROR to retrieve error info and pass that back with COMRETURNERROR
      ENDIF

      SQLSETPROP(m.lnCon, 'Asynchronous', .T.)
      m.lnRet = SQLEXEC(m.lnCon, m.lcSql)

      DO WHILE .T.
        DO CASE
           CASE m.lnRet = 1
              EXIT
           CASE m.lnRet = 0 AND THIS.CallInfo.Aborted()
              SQLCANCEL(m.lnCon)
              EXIT
           CASE m.lnRet = -1
              SQLDISCONNECT(m.lnCon)
              && use AERROR to retrieve error info and pass that 
              && back with COMRETURNERROR
        ENDCASE
        Sleep(250) && you can vary the period for responsiveness
        m.lnRet = SQLEXEC(m.lnCon)
      ENDDO

      SQLDISCONNECT(m.lnCon)
      RETURN m.lnRet
   ENDFUNC

ENDDEFINE

to abort the thread:

THISFORM.oThread.AbortCall()

 

In the future at least have a look at the documention, everything in the code above is documented!

I'm not going to answer any common questions like these in the future!