Solved

Multitasking with VC++

Posted on 2001-06-29
7
764 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DataAdapter, stored procedures and parameters 2 51
How Does Quick Books store date / time? 3 104
Need example 5 122
Using MS Code on my Mac 6 68
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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