954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

QueueUserWorkItem not calling the function

Hi All,
Why my QueueUserWorkItem is not at all working. My code is here:

typedef struct
{
    PCHAR URL[MAX_URL] ;
    PCHAR DestinationPath ;
}MAINDATA, *PMAINDATA ;
 
int main(int argc, char * argv[])
{
	PMAINDATA	pData ;
		
	BOOL bQuwi ;
	DWORD dwIndex ;
	PCHAR pURL ;
 
        pData = (PMAINDATA)malloc(sizeof(MAINDATA)) ;
	pData->DestinationPath = NULL ;
	pData->URL[0] = 0 ;
 
        do
	{
	
		if(argc < 3)
		{
			printf("Main Error-> Not Enough Arguments\n") ;
			break ;
		}
		printf("START\n") ;
		pData->DestinationPath = argv[2] ;
		while((pURL = (PCHAR)GetNext_FileList(pContext)) != NULL)
		{
			TempURL = StrDupA(pURL) ;
			pData->URL[dwIndex] = (PCHAR)TempURL ;
			dwIndex++ ;
		}
		dwTotalNumberOfURL = dwIndex ;
 
		bQuwi = QueueUserWorkItem(MyThreadProc,(PVOID) pData,      
                                                             WT_EXECUTEDEFAULT) ;
		if ( !bQuwi )
			printf("Main: QueueUserWorkItem Failed\n");
 
		printf("SUCCESS\n") ;
	
	}while(FALSE) ;
        return 0 ;
}
 
DWORD CALLBACK MyThreadProc( LPVOID lpParam ) 
{ 
    PMAINDATA pData ;
    
	pData = (PMAINDATA)lpParam ;
 
	DownloadFile(pData->URL, pData->DestinationPath) ;
    
    return 0 ; 
}

I have not submitted the whole code. So please bypass the declaration and free memory errors. The only problem I am facing is that QUWI is not calling my "MyThreadProc" function although it is returning TRUE.

Abhineet.Ayan
Newbie Poster
4 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

Are you giving QUWI enough time to finish?
It looks like you're queuing the thread, then exiting.

Have a look at this:
http://developer.amd.com/documentation/articles/pages/125200687.aspx
In this code, when the last thread finishes, it signals an event, which the main function waits for before exiting.

DeanMSands3
Junior Poster
185 posts since Jan 2012
Reputation Points: 37
Solved Threads: 26
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: