mfc >> GUI update

by RAN » Tue, 28 Aug 2007 00:31:04 GMT

Hi,

I have a serverprogram with a CListCtrl, displaying 2 collumns with
BytesIn and BytesOut.
Those BytesIn and BytesOut represent the number of bytes comming in
and going out of the server socket. If i startup 10 clients that
connect to the server, they al send about 100 bytes of data at a 1ms
interval. The problem is that my server GUI is not getting updated,
how do i get this done? Is it something with PeekMsg() ? I dont want
to make everything threaded...



mfc >> GUI update

by Joseph M. Newcomer » Tue, 28 Aug 2007 01:00:48 GMT


You should not be doing such high-frequency I/O in the main GUI thread. And you should
not be considering PeekMessage as a solution; do the I/O in a separate thread.

You can explicitly call UpdateWindow after making modifications, but the problem is much
deeper than just a screen update. You have a very high interaction rate. Even if you are
using separate threads and using PostMessage to post messages to the main GUI thread, this
means that you always have something in the message queue, since you will be having
updates sent, on the average, every 100us (10 clients with 1ms updates), so the WM_PAINT,
which is not sent until the queue is empty, is never sent. In addition, given the high
data rate, there is a chance you could start losing messages. See my essay on the use of
I/O Completion Ports to avoid this problem, on my MVP Tips site.

If you move sockets to separate threads, check out my essay on multithreaded sockets (do
not trust the MSDN article, which is buggy beyond usability). If you are trying to
support this data rate in a single thread, you are going to have problems with saturating
the thread's capability to respond to user input.

Given this high data rate, and the inability of users to see anything updating too
quickly, you might be better off just recording the values in an array, and on a WM_TIMER
notification, perhaps 20 times a second or even less, updating the display. (This won't
work if everything is in the main thread because you still need the WM_PAINT, so you would
have to also call UpdateWindow). If you store the information in an aligned DWORD, you
don't even need to synchronize the reading from and writing to the array (except to extend
it), because the hardware will do that, and if you miss an update, you'll catch it the
next time around.
joe




Joseph M. Newcomer [MVP]
email: XXXX@XXXXX.COM
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



mfc >> GUI update

by David Ching » Tue, 28 Aug 2007 01:10:49 GMT





Is the socket running on a worker thread or the UI thread? IOW, can you
drag the window around with the mouse while its running, and does the UI
move, or is it frozen?

Regardless, the UI isn't given a chance to update. Either because you're
saturating the message pump with too many messages, and no WM_PAINT can
occur until all of them are gone, or else you're not pumping messages at all
due to the fact the socket is monopolizing your UI thread.

-- David




GUI update

by RAN » Tue, 28 Aug 2007 03:31:30 GMT





So i have to make my CAsyncSocket classes threaded for this to work,
it won't work at all whithout them i guess.
I will study your essay on threaded sockets, and hopefully i
understand it (this might be a problem for a newbie) to make my
program work the way it suppose to work. Can i download the source of
this essay somewhere ??



GUI update

by RAN » Tue, 28 Aug 2007 03:43:57 GMT

n Aug 27, 9:31 pm, RAN < XXXX@XXXXX.COM > wrote:

Ah, Yes i found the download link for the sources, thank you!



GUI update

by RAN » Tue, 28 Aug 2007 03:51:31 GMT

n Aug 27, 9:43 pm, RAN < XXXX@XXXXX.COM > wrote:


I am using Visual C++ 6.0 Enterprise Ed.
I have downloaded the source for the threated sockets from Joseph M.
Newcomer's site and try to build it, it gives a compile error:

fatal error C1083: Cannot open include file: 'strsafe.h': No such file
or directory
Error executing cl.exe.

AsyncClient.exe - 1 error(s), 0 warning(s)

What must i do ? Do i need this file ?



GUI update

by Mark Salsbery [MVP] » Tue, 28 Aug 2007 04:18:17 GMT

don't think you'll have that file in VC6.

You can comment it out. You may have to adjust the code for any calls to
the "safe" string functions.

Mark


--
Mark Salsbery
Microsoft MVP - Visual C++


"RAN" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...




GUI update

by RAN » Tue, 28 Aug 2007 04:56:16 GMT

n Aug 27, 10:18 pm, "Mark Salsbery [MVP]"
<MarkSalsbery[MVP]@newsgroup.nospam> wrote:

Ok, i have commented the strsafe.h away. But now i have some new
problems:

ErrorString.cpp
C:\Program Files\DevStudio\MyProjects\threadsockets\mvp_tips\MFCAsync
\AsyncClientServer\Common\ErrorString.cpp(40) : error C2039:
'SHGetFolderPath' : is not a member of '`global namespace''
C:\Program Files\DevStudio\MyProjects\threadsockets\mvp_tips\MFCAsync
\AsyncClientServer\Common\ErrorString.cpp(40) : error C2065:
'SHGetFolderPath' : undeclared identifier
C:\Program Files\DevStudio\MyProjects\threadsockets\mvp_tips\MFCAsync
\AsyncClientServer\Common\ErrorString.cpp(40) : error C2065:
'CSIDL_SYSTEM' : undeclared identifier
C:\Program Files\DevStudio\MyProjects\threadsockets\mvp_tips\MFCAsync
\AsyncClientServer\Common\ErrorString.cpp(40) : error C2065:
'SHGFP_TYPE_CURRENT' : undeclared identifier
Log.cpp
SocketThread.cpp
TracePacket.cpp
UnicodeFont.cpp
C:\Program Files\DevStudio\MyProjects\threadsockets\mvp_tips\MFCAsync
\AsyncClientServer\Common\UnicodeFont.cpp(24) : error C2065:
'StringCchCopy' : undeclared identifier
Generating Code...
Error executing cl.exe.

AsyncClient.exe - 5 error(s), 0 warning(s)

I thought that if i included # include "shlobj.h" the problem for the
SHGetFolderPath would be solved, but it keeps giving this error..
Maybe someone knows this source and could help me out.



GUI update

by RAN » Tue, 28 Aug 2007 05:46:00 GMT

n Aug 27, 10:56 pm, RAN < XXXX@XXXXX.COM > wrote:

Maybe someone with a version of VC6.0 could download the project
at :http://www.flounder.com/kb192570.htm#CConnectSoc::SetTarget

and compile it and tell me what i must do to resolve these compile
errors?
Is there a version that compiles for VC6?



GUI update

by Dan Bloomquist » Tue, 28 Aug 2007 05:54:05 GMT






Here is how you fix a problem like this.
Search on 'SHGetFolderPath' for the document page. At the bottom of the
page you will see:
Function information:
Header shlobj.h

It turns out the other four are in that same header.

Best, Dan.



GUI update

by Joseph M. Newcomer » Tue, 28 Aug 2007 07:51:27 GMT

Actually, it works fine in VC6, but it isn't delivered with the product; you have to
download the latest (VC6-compatible) Platform SDK to get it. I forget which one that is,
but if you go to the Microsoft Web site, you'll find the download. Later Platform SDKs
won't work with VC6, but I was using this header file in VC6 for years.
joe

On Mon, 27 Aug 2007 13:18:17 -0700, "Mark Salsbery [MVP]"


Joseph M. Newcomer [MVP]
email: XXXX@XXXXX.COM
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


GUI update

by Joseph M. Newcomer » Tue, 28 Aug 2007 07:52:53 GMT

ou also have a very old copy of the shell library; get a newer copy. This will work with
VS6 if you have the most recent VC6-compatible platform SDK.
joe

On Mon, 27 Aug 2007 13:56:16 -0700, RAN < XXXX@XXXXX.COM > wrote:

Joseph M. Newcomer [MVP]
email: XXXX@XXXXX.COM
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Similar Threads

1. Thread and GUI update problem

To all, 

I have a GUI program (use c#), and I have create a Thread for loading
some bulk data, I also arrange the GUI program like this:

1) load a form showing "Wait for loading..." etc
2) a Thread is then created to load the bulk data
3) after the thread has completed, close the "Wait for loading" form
4) show the main form for the GUI program

The problem is that if I show the "waiting" form, that form's GUI will
not work properly (no repaint event and hangs around, ie. a blank
window), the worse thing is that the Thread may not work properly too
(actually it will stop executing, waiting for locks, maybe ??)

But if I start the Thread without showing any forms; it works
perfectly ????!

What's wrong ?? (the same things happen under .Net Compact Framework)

[code snippet for the main GUI form]
	public class Trial04_02 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button1;
		private System.ComponentModel.Container components = null;
		private Trial04_01 mFrmSplash;
		private Thread mThr_Main;
		private System.Windows.Forms.ListBox listBox1;
		private CommonEngine02 mCEng;

		public Trial04_02()
		{
			InitializeComponent();
			init ();
		}

		private void InitializeComponent() {}

		protected void init () 
		{
			// 1st show splash form
			this.mFrmSplash = new Trial04_01 ();
			//this.mFrmSplash.Show ();

			// 2nd create a thread to load sth...
                        // CommonEngine02 is a class containing the 
                        //  data loading function
			this.mCEng = new CommonEngine02 ();					this.mThr_Main = new Thread
                          (new ThreadStart (this.mCEng.threadTask));
			this.mThr_Main.Start ();
			this.mThr_Main.Join ();
			this.mFrmSplash.Close ();
			
			// 3rd other setup(s)
                        // get back the loaded data
			System.Collections.ArrayList oArr 
                         = this.mCEng.getArr_Data ();
			for (int i=0; i<oArr.Count; i++) 
			{
				this.listBox1.Items.Add (oArr[i]);
			}
			this.Show ();
		}

		static void Main () 
		{
			Application.Run (new Trial04_02 ());
		}
	}
}

[/code]


From Jason (Kusanagihk)

2. Update GUI from RunWorkerCompleted - CSharp/C#

3. Multithreading and updating the GUI

Hi all,

I have a workerthread which notyfies the GUI through a delegate like this:

        if (deviceInsertedDelegate) deviceInsertedDelegate(stringAddress);

Now in my Form's code I write code like this:

        private delegate void DeviceInsertedCallback(string Address);

        public void DeviceInserted(string Address)
        {
            if (this.label1.InvokeRequired)
            {
                Invoke(new DeviceInsertedCallback(DeviceInserted), new 
object[] { Address });
            }
            else
            {
                label1.Text = "Login : " + Address;
            }
        }

Now my question is if it's possible not to have the code as above in my 
form. Would it be possible to synchronize (or whatever) from within my 
worker thread.

Thanks in advance,

Bart 

4. Boilerplate example for updating GUI inside a C# Thread - CSharp/C#

5. c# and updating the gui from a thread

Hello,

I'm aware of the ways MS has recommended updating the gui from a
thread.

eg.
BeginInvoke(StartedExaminingFile, new object[] { file });

But, I really don't like this solution. The fact that you're passing an
array of objects means if the function signature changes, the invoke
would fail terribly.

With all the code-generation that goes on with .net (ie. datasets etc),
couldn't MS make a wrapper for this call? It just seems
uncharacteristic of .net to not strongly type the parameters,
considering the introduction of things like generics (and other
mechanisms for strongly typing).

6. Updating GUI controls from threads - CSharp/C#

7. Very Fast Updates to GUI - blank out

I have an application that does alot of work and calculations.  It
updates it's internal status on a windows form.  When I debug single
step the numbers appear just right on the form.  When I run the program
in normal mode the text boxes to which the info is displayed just blank
out.  Sometimes the entire form just turns all white.  I get the
impression that the updates are happening too fast or something like
that.

What's going on?  Any ideas?

8. List View GUi Not updating - CSharp/C#