CFtpQueue::Start Method  
 
BOOL Start(
  DWORD dwQueueMode,  
  FTPEVENTPROC lpEventProc,  
  DWORD_PTR dwParam  
);

The Start method begins transferring files in the queue.

Parameters

dwQueueMode
An unsigned integer which specifies which files in the queue should be transferred. It may be one of the following values:
Constant Description
FTP_QUEUE_ALL All files in the queue should be transferred.
FTP_QUEUE_DOWNLOAD Transfer only those files which have been queued for download.
FTP_QUEUE_UPLOAD Transfer only those files which have been queued for upload.
lpEventProc
Specifies the procedure-instance address of an application defined callback function. For more information about the callback method, see the description of the FtpEventProc callback method. If this parameter is NULL, there will be no callback notifications.
dwParam
A user-defined integer value that is passed to the callback method. If the application targets the x86 (32-bit) platform, this parameter must be a 32-bit unsigned integer. If the application targets the x64 (64-bit) platform, this parameter must be a 64-bit unsigned integer.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, it will return zero. To get extended error information, call GetLastError.

Remarks

Queued file transfers are performed asynchronously using a background worker thread. If you provide the address to an event callback function, that method will always be invoked in the context of the queue manager thread. You must ensure that any access to global or static variables are synchronized, otherwise the results may be unpredictable. It is recommended that you do not declare any static variables within the callback function itself and you should avoid calling any methods which could cause the thread to block. For example, you should not attempt to establish other network connections from within the event handler.

If your application has a graphical user interface, you should never attempt to directly modify a UI control from within the callback method. Controls should only be modified by the same UI thread that created their window. One common approach to address this issue is to post a user-defined message to the main window to signal that the user interface needs to be updated. The message handler would then process the user-defined message and update the user interface as needed.

The callback function specified by the lpEventProc parameter must be declared using the __stdcall calling convention. This ensures the arguments passed to the event handler are pushed on to the stack in the correct order. Failure to use the correct calling convention will corrupt the stack and cause the application to terminate abnormally.

The dwParam parameter is commonly used to identify the class instance which is associated with the event that has occurred. Applications will cast the this pointer to a DWORD_PTR value when calling this function, and then the event handler will cast it back to a pointer to the class instance. This gives the handler access to the class member variables and methods.

The Wait method can be used to wait for the queue manager to complete processing the transfer queue.

Example

// Create a new queue
CFtpQueue *pQueue = new CFtpQueue();

// Add a file to the queue
pQueue->AddFile(lpszLocalFile, lpszRemoteFile);

// Start the queued file transfers and wait for it to complete
if (pQueue->Start(FTP_QUEUE_ALL))
{
    pQueue->Wait(INFINITE);
    pQueue->Stop();
}

// Remove all files from the queue
delete pQueue;

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csftpv12.lib

See Also