Solved

Multitasking with VC++

Posted on 2001-06-29
7
750 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now