Solved

Multitasking with VC++

Posted on 2001-06-29
7
760 Views
Last Modified: 2013-12-03
I have written a VC++ program. When this program runs it completely blocks all other programs. Well at least it seems that way since it blocks the handling of the user interface.

How can I make it yield to other processes now and then. In VB and Access I would use a call to DoEvents, but I haven't been able to find something similar for VC++.

If I would turn this program into a service would it then block out all other services?
0
Comment
Question by:patrickl
7 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6237735
Some more information about what you are doing would really help.
0
 
LVL 3

Expert Comment

by:MDarling
ID: 6237773
Sleep() would yield to other processes.

But if you're running on NT (and to lesser extent 9x) your other programs should get scheduled anyway.

Regards,
Mike.
0
 
LVL 2

Assisted Solution

by:Chandra V
Chandra V earned 100 total points
ID: 6237893
You write your own DoEvents function and call it in your waiting loop instead of using Sleep

void DoEvents()
{
     MSG msg;
         
     // Process existing messages in the application's message queue.
     // When the queue is empty, do clean up and return.
     while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
     {
          if (!AfxGetThread()->PumpMessage())
               return;
     }
}
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 5

Author Comment

by:patrickl
ID: 6238127
OK I'll check these suggestions out.

Just to add some extra info:

The software in question is an "ftp client server". It is basically an automated ftp client. It ftp's files that are placed into a directory to several ftp servers.

The trouble is when the connection to an ftp server times out the GUI hangs while it waits for the timeout. But also when it is sending or doing tasks out of the event queue loop.

The software is running on a Windows NT 4.0 server.
0
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 6238157
>>The trouble is when the connection to an ftp server times out the GUI hangs while it waits for the timeout.
But also when it is sending or doing tasks out of the event queue loop.


This is due to using BLOCKING WINSOCK calls in the main thread of your application.  Once a network call is made, it does not return to the caller until it completes, so the thread "blocks".  Since the GUI depends on the thread returning to Windows to be able to process the next message and remain responsive to the user, it hangs.

This is poor GUI design since users get frustrated when the application appears unresponsive.  They don't know if it's working or it's hung.  There are two solutions:

1) If you must use the blocking WINSOCK calls, put them in a separate thread.  Then, they can complete in their own time but the main thread can still handle Windows messages and be responsive.  

2) My preferred method is to use WINSOCK ASYNCHRONOUS calls which are those beginning with WSA.  These, return immediately under all conditions.  They then post a message to your app when the operation completes and you can deal with it in the main message loop when it comes.  These take a bit of getting used to if you have only used the standard sockets library but once you spend some time using them you'll see that they fit into the Windows architecture better than other methods.  
0
 
LVL 5

Author Comment

by:patrickl
ID: 10569620
Sorry, forgot all about this question. I guess I missed a notification mail since I completely missed that last response!

I used cvallabhaneni's answer for something else already and I just read jhance's reply which would probably work. In the mean time we bought WS-FTP Pro which does this stuff standard so no need to program things myself anymore.

Thanks all for the help!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question