mfc >> Returns immediate function

by PPC DEV » Wed, 26 Nov 2003 03:16:39 GMT

Hi all,

I know that the function CeRapiInitEx returns
immediately. No wait for processing.

I want to implement such a function. Returns immediate.
no wait.

How do I implement such a function?


Thanks
Ko


mfc >> Returns immediate function

by Gaetano Sferra » Wed, 26 Nov 2003 03:27:18 GMT


You might create a UI thread that do the work, launch it in the "non-wait"
function and return immediatly to the caller.
When the thread done it's works, you can post an application message to
return the results....

Greetings,
Gaetano Sferra

"PPC DEV" < XXXX@XXXXX.COM > ha scritto nel messaggio






mfc >> Returns immediate function

by Tom Serface » Wed, 26 Nov 2003 03:29:52 GMT

Start a thread, return from function, thread processes things that need to
be done then exits.

Tom







Returns immediate function

by anonymous » Wed, 26 Nov 2003 22:27:54 GMT

Thank You guys.
That is exactly what I want.
Here is my function.

UINT AsynchronousFunction(LPVOID phr)
{
CallTheFunctionItStuck();// THIS FUNCTION TAKES TOO LONG
OR HANGS...
return 0;
}

// This is caller function...

void CLightningPCDoc::OnCallerFunction()
{
CWinThread* pWorkerThread=AfxBeginThread
(AsynchronousFunction,NULL);
// I WANT TO KILL THREAD HERE ..
}

Problem is that I don't know how to kill that worker
thread in the case if it takes too long or hangs.
If I quit from application, application remains in the
memory since the worker thread is still working.

Any Idea how to kill this worker thread?

Thanks
KO

things that need to




Returns immediate function

by Scott McPhillips [MVP] » Thu, 27 Nov 2003 10:15:59 GMT





It depends on what the worker thread is doing. Not all cases can be
solved cleanly. If it is stuck in your own thread code then you can add
WaitForMultipleObject calls within the inner loop, and use SetEvent in
the main thread to signal the thread to quit. If it is stuck down
inside a call to Microsoft then you've got big trouble. Except in some
cases, like a winsock call, you can close the socket from the main
thread, which makes the stuck call return with an error code.

--
Scott McPhillips [VC++ MVP]



Returns immediate function

by ppc_dev » Mon, 01 Dec 2003 22:29:06 GMT

Thank you All.

Since the function CallTheFunctionItStuck is not mine, I cannot
control that function.
That's why I told that I don't see any way to kill the thread since it
stuck in that CallTheFunctionItStuck function EVER.

So, I worked around and found that the best way to work is develop my
own CallTheFunctionItStuck2 function so that it is totally under my
control and I can kill the thread from that function.

That is the way I solved that problem.

Thank you for your idea anyway.

Mr PPC.





Similar Threads

1. Help with XmlNode - HasChildNodes always returns true even no immediate child exists - CSharp/C#

2. Returns immediate database

Hi all,

 I know that the function CeRapiInitEx returns immediately. No wait for processing.

 I want to implement such a function. Returns immediate. no wait.

 How do I implement such a function?


Thanks
Ko

3. Help calling function from DLL and processing returned value (Can not marshal return value) - CSharp/C#

4. function doesn't return simply skip the return line

Hello to all, i have the following functions:

string File::readLine(){
	char ch;
	string str;
	ch = read();
	while(ch != LF && ch != CR && ch != -1){
		str.append(1,ch);
		ch = read();
	}
	if(ch == -1){
		cout << "this line could not be read" << endl;
		exit(1);
	}
	//take care of situation where the loop exited with LF but
	//on a system that has CR.
	int tmp = file->tellg();
	if(read() != CR){ //if no CR available on system, return the get
pointer to it's correct location.
		file->seekg(tmp);
	}
	return str;
}

the function is executed correctly but in the end it skips the "return
str" line,
and tun flies with an error.
debugging took me to a qt class moc_myclass.cpp (it's a qt project in
eclipse)
to a line where it says "_id -= 1;"
inside a function called "int myclass::qt_metacall(...)"

can anyone help me??????????

5. return type of a function that returns a local variable

6. Forgetting to write a return in a function returning a value

Why doesn't my compiler (g++) flag something like this as an error:

int main()
{
}

?

7. Accessor functions - return by value or return by reference

8. Want to create a function which returns a value obtained from a callback function

Hello

I want to write a C++ function which returns a Windows handle.  I need
to call a callback function to find the Window.  The specific function
is EnumChildWindows.

As the final parameter of EnumChildWindows I can pass a pointer back
to my class.  so I can access class functions ok.  I thought that I
could have a member variable in the class which is an HWND.  Then the
this variable could be updated by EnumChildWindows if a window handle
is found.  then when the function returns I just take the value in the
variable as the first found windows handle.

I suppose that would work but it doesn't feel so elegant.  Has anyone
got any better ideas?

Angus