ctaDestroyContext

Destroys a context.

Prototype

DWORD ctaDestroyContext ( CTAHD ctahd)

Argument

Description

ctahd

Context handle.


Return values

Return value

Description

SUCCESS

 

CTAERR_INVALID_CTAHD

An invalid context handle was passed as an argument to a function, or the context was destroyed by another thread.

CTAERR_INVALID_SEQUENCE

An open service, close service, or destroy context call is pending on the context.

CTAERR_NOT_INITIALIZED

Natural Access is not initialized. Call ctaInitialize first.

CTAERR_SVR_COMM

Server communication error.


Events

CTAEVN_DESTROY_CONTEXT_DONE

Details

ctaDestroyContext destroys the context and closes all open services on that context. This function is asynchronous and returns immediately. The application must wait for the DONE event before the context is destroyed and any resources associated with it are released.

ctaDestroyContext closes pending open or close service calls. Wait until the pending function completes and then call this function.

If an application sets the CTA_CONTEXT_PERSISTENT flag in ctaCreateContextEx, the shared context continues to exist on the server even when the originating application is disconnected. When the last application attached to the context calls ctaDestroyContext, the context is destroyed.

Refer to Closing services for more information.

See also

ctaAttachContext, ctaCreateContext

Example

/* 
 * Destroy the context and the queue. It would be equivalent to just
 * destroy the queue since this implicitly destroys the context and 
 * closes all open services. 
 */
void DemoDestroyContext(DEMOCONTEXT *cx)
{
    CTA_EVENT event;

    /* Destroy the context */
    ctaDestroyContext( cx->ctahd );

    /* Wait for the services to be closed and the context destroyed */
    do
    {
        ctaWaitEvent( cx->ctaqueuehd, &event, CTA_WAIT_FOREVER ); 
    } while (event.id != CTAEVN_DESTROY_CONTEXT_DONE);
      
    ctaDestroyQueue( cx->ctaqueuehd );
}