|
-
May 31st, 2005, 04:01 PM
#1
Form Refresh Issues
I hope this makes sense, so here goes:
I have a form that runs in a loop. It uses comm ports, local and remote database lookups. When I start a process, I want to reflect certain information on the console for the operator to see. What is happenning is that some information is reflected correctly, but others are not (they show up after the running process completes).
I am not currently using this in a multi-threaded environment (yet), this is only the first version.
example (m_MDTData is a text field):
Code:
m_MDTData.SetWindowText("Write this now!!!");
RefreshMDT(); // remote database lookup
...
// elsewhere
void RefreshMDT(){
// do a lot of stuff
...
// when done, print the following
m_MDTData.SetWindowText("Write this when finished!!!");
}
When this runs, only the last print statement will print. The RefreshMDT process() may take up to 5 seconds to finish, so the first statement would be nice to see.
I hope this makes sense, because I am stumped as to why the first line fails to print.
There are 10 types of people in the world, those that understand binary and those that don't. 
Using VS 2010
-
May 31st, 2005, 04:13 PM
#2
Re: Form Refresh Issues
You're terminology is confusing. Form is a VB and .NET term. In Windows programming they are called "windows", and a particular class of windows in MFC are called dialogs, which is probably what you have.
When I start a process, I want to reflect certain information on the console for the operator to see.
OK, so is this a dialog based app or a console based one?
Your ode snippet is a little bit vague...
-
June 1st, 2005, 07:47 AM
#3
Re: Form Refresh Issues
You are correct, my post was a little vague. Let's see if I can clarify a little.
THis is a C/C++ V6 application using a common dialog. The dialog has several text fields on it that get populated via a database. Data is retrieved from the database and displayed. The process tree is something like this:
while(true){
Synchronize local/enterprise database
while(not EOF){
Retrieve next active data record from local DB
Prepare datagram for processing
Send datagram via comm port to machine on factory floor
Retreive response from machine
process retrieved data
update local database
}
}
The process works flawlessly. What I want to address is the dialog text fields not showing active data until AFTER the process is completed. In other words, I would have thought that the text fields would reflect the new data as soon as I call the m_MDTData.SetWindowText("..."), which is not the case at all.
Assume that the application just launched and default text "Process Initialized" is displayed in the MDTData text field. The following is a (poor) example of setting the data:
Code:
m_MDTData.SetWindowText("Begin Process MDT 001");;
m_MDTNum.SetWindowText("001");
m_MDTDesc.SetWindowText("Machine 001");
callMyProcessTree(); // takes about 5 seconds
If this is run, the process will run, but the MDTData, MDTNum, and MDTDesc fields will not reflect the information until AFTER callMyProcess() finishes!
There is a very noticable delay in the dialog's ability to display the data prior to the process running. I am looking for the proper method to change the displayed information so the the dialog is always showing the data I want when I want it to be shown.
I hope that helps a little...
There are 10 types of people in the world, those that understand binary and those that don't. 
Using VS 2010
-
June 1st, 2005, 09:40 AM
#4
Re: Form Refresh Issues
 Originally Posted by rick7423
If this is run, the process will run, but the MDTData, MDTNum, and MDTDesc fields will not reflect the information until AFTER callMyProcess() finishes!
There is a very noticable delay in the dialog's ability to display the data prior to the process running. I am looking for the proper method to change the displayed information so the the dialog is always showing the data I want when I want it to be shown.
That's because your lengthy process is executed in the your main thread, which is also responsible for processing messages and updating the GUI - while it is executed, it prevents the GUI thread from receiving messages and updating the window. You could of course add an UpdateWindow() call after the SetWindowText() calls, but it would still leave your UI unresponsive (which is generally to be avoided). The better solution is to put your process in a worker thread, and have it send a user-defined message to your main window when it's done.
-
June 1st, 2005, 09:57 AM
#5
Re: Form Refresh Issues
Yes, that is what I am intending on doing now that the utility is stable as a single threaded app ("do one thing at a time, do it very well, then move on").
This leads to another issue, if I make this a multi-threaded app and the thread needs to set some value on the dialog, such as an error or warning message, can the worker thread send these to the dialog to be displayed immediatly?
There are 10 types of people in the world, those that understand binary and those that don't. 
Using VS 2010
-
June 1st, 2005, 11:54 AM
#6
Re: Form Refresh Issues
 Originally Posted by rick7423
This leads to another issue, if I make this a multi-threaded app and the thread needs to set some value on the dialog, such as an error or warning message, can the worker thread send these to the dialog to be displayed immediatly?
Yes, as I said above: You would typically do that by sending a user-defined message to the dialog.
-
June 1st, 2005, 02:01 PM
#7
Re: Form Refresh Issues
Thanks for the help. Now I have to find out how to add this functionality.
There are 10 types of people in the world, those that understand binary and those that don't. 
Using VS 2010
-
June 1st, 2005, 03:14 PM
#8
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|