
How to show progress during long document open?
Only if you guarantee that whatever is being done is properly synchronized, that is, if
the worker thread can write to the CDocument, whatever it is writing must be protected by
a CRITICAL_SECTION; or, if it is reading from the CDocument but the GUI thread can be
writing to the CDocument, likewise you must protect the data. Concurrent, unsynchronized,
access is permitted only in the cases where the values are ONLY being read but not
modified by the two threads (e.g., if the GUI thread sets up data before spawing the
worker thread, and does not change it until it knows the worker thread has terminated,
this is a form of synchronization, but does not require a CRITICAL_SECTION). And the
worker thread must not modify the tree control directly, only by sending requests to the
GUI thread to perform the modifications.
joe
Quote:
>Thanks.
>This worker thread will be adding information into a treeview on the CView
>of the document, is it safe to do this from a worker thread , e.g. pass the
>worker thread a pointer to my CDocument object?
>> There are some issues to consider. If you are off computing, the GUI is
>not being
>> refreshed, so you won't see the progress bar move. The simplest way to
>handle something
>> like this is to do the work in a thread, and use PostMessage to send
>information back to
>> the main GUI thread to update the progress bar. Note that you will have to
>provide
>> suitable synchronization on the document to keep it from being used
>improperly during the
>> update.
>> joe
>> On Thu, 7 Mar 2002 12:45:00 -0000, "Paul Higgs"
>> >I have an MFC MDI Document/View application. Basically the Document is
>just
>> >a representation of data from an SQL Server. At the moment I populate it
>> >with data during the OnNewDocument call. However as it takes 10-20
>seconds
>> >to populate there is no application window showing during start-up of the
>> >program during this process. I would like to be able to show some
>progress
>> >for this?
>> >Any ideas on the best way to do this?
>> >Cheers
>> >Paul Higgs
>> Joseph M. Newcomer [MVP]
>> Web: http://www3.pgh.net/~newcomer
>> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
Joseph M. Newcomer [MVP]
Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm