Solved

Multitasking with VC++

Posted on 2001-06-29
7
755 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

14 Experts available now in Live!

Get 1:1 Help Now