From: Eric Kaplan on
I have a function that will download XML from internet and load XML
data into database.

The function will take 5 - 20 minutes to finish.

I heard I should use event sink (event listener) when function is
finished the task, then it will notify the caller.

So I am planning to create a seperate thread to do the long XML
loading function by using - _beginthreadex()

But how to create a notification / event sink / event listener in C++?

any library can easily just a library function call?

or any sample source code on the internet?

Thanks

From: Eric Kaplan on
how about if my library / DLL dont' use MFC at all,

but may be my friend's appliction that make use of my library / DLL
use MFC i don't know, in this case, can I use _beginthreadex() ???

also where is your essay on worker thread??

Thanks again


>See my essay on worker threads.
>
>Note: you must *not* use _beginthread in MFC; you *must* use AfxBeginThread.
>
>I would pass in a CWnd* in some form or other, and PostMessage to it when the worker
>thread is finished.
> joe
>
From: Eric Kaplan on
If I want to start another process instead of a new thread, how can I
do that?

since the loading of XML into database takes at least 5min to 30 min.

how to I notify the caller if i start another process instead of
another thread ?
From: Anders Karlsson on
On Sat, 12 Apr 2008 14:44:53 -0700, Eric Kaplan
<tobycraftse(a)yahoo.com> wrote:

> I have a function that will download XML from internet and load XML
> data into database.
>
> The function will take 5 - 20 minutes to finish.
>
> I heard I should use event sink (event listener) when function is
> finished the task, then it will notify the caller.
>
> So I am planning to create a seperate thread to do the long XML
> loading function by using - _beginthreadex()
>
> But how to create a notification / event sink / event listener in C++?
>
> any library can easily just a library function call?
>
> or any sample source code on the internet?
>
> Thanks

If you want to download the XML-file in a separate thread just
create a function that downloads the file and then launch it in its
own thread passing a pointer to the parent object/window - depending
in which environment you are running.

When the download is complete, you post a message to the parent
object/window saying that you are done. You can also continously post
messages to the parent to display the progress of the copy - probably
a good idea in your case since you say it takes so long to complete.

hth/Anders.
--
A: People bitching about top-posting

> Q: What's the most annoying thing on USENET?
From: Carmen Sei on
are you meaning I should create a new thread from the primary thread
currently running?

then I pass a pointer of status to that thread like -

==============================
int * status;

// a new thread get initialized and pass a pointer of the status
// to the new thread
ThreadX * o1 = new ThreadX( &status );

// create the thread using _beginthreadex()
hth1 = (HANDLE)_beginthreadex(
NULL, // security
0, // stack size
ThreadX::ThreadStaticEntryPoint,
o1, // arg list
CREATE_SUSPENDED, // so we can later call ResumeThread()
&uiThread1ID
);

// after created the thread, primary thread continue execute
// primary thread keeps checking the status
// (integer value 1 = finish, integer value 0 = not finish)


==============================

ThreadX::ThreadX( int * status )
{
// if the XML thread finish loading data
// may be after 10 min, the status flag is set to 1 = finished
currentstatus = status ;
}






> If you want to download the XML-file in a separate thread just
>create a function that downloads the file and then launch it in its
>own thread passing a pointer to the parent object/window - depending
>in which environment you are running.
>
> When the download is complete, you post a message to the parent
>object/window saying that you are done. You can also continously post
>messages to the parent to display the progress of the copy - probably
>a good idea in your case since you say it takes so long to complete.
>
>hth/Anders.