Threads #7

I was wondering if someone could tell me how to implement a couple of 
threads.  I have an MFC application which launches a Command line 
application using 4 different commandline arguments.  This works fine using 
CreateProcess, but I also want to update a progress bar to the amount of how 
long the command line application stays active.  I created a thread to 
update the progress bar and it works, but I can't figure out how to update 
the progress bar at the same time that the exernal process is active.  The 
program always waits until the process is complete before updating the 
progress bar.  Any help would be appreciated.

   Z.K. 


0
nospam2791 (369)
3/20/2008 6:39:55 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
499 Views

Similar Articles

[PageSpeed] 8

Z.K. wrote:
> I was wondering if someone could tell me how to implement a couple of 
> threads.  I have an MFC application which launches a Command line 
> application using 4 different commandline arguments.  This works fine using 
> CreateProcess, but I also want to update a progress bar to the amount of how 
> long the command line application stays active.  I created a thread to 
> update the progress bar and it works, but I can't figure out how to update 
> the progress bar at the same time that the exernal process is active.  The 
> program always waits until the process is complete before updating the 
> progress bar.  Any help would be appreciated.

You need to supply more information.

How are you detecting that the command line program has finished?

And you mention a couple of threads at the beginning. But later only one.

-- 
David Wilkinson
Visual C++ MVP
0
no-reply8010 (1791)
3/20/2008 7:10:06 PM
"Z.K." <nospam@nospam.net> wrote in message 
news:ePaiLnriIHA.3512@TK2MSFTNGP03.phx.gbl...
>I was wondering if someone could tell me how to implement a couple of 
>threads.  I have an MFC application which launches a Command line 
>application using 4 different commandline arguments.  This works fine using 
>CreateProcess, but I also want to update a progress bar to the amount of 
>how long the command line application stays active.  I created a thread to 
>update the progress bar and it works, but I can't figure out how to update 
>the progress bar at the same time that the exernal process is active.  The 
>program always waits until the process is complete before updating the 
>progress bar.  Any help would be appreciated.


Apparently you have stopped your main thread from processing messages while 
waiting for the external process to complete.  That will prevent updates of 
the progress bar.  It will also lock up the secondary thread that is 
attempting to update the progress bar.

The solution is: don't block the main thread, it should always return soon 
to MFC so messages can be processed.  If you need a wait or wait loop to 
detect external process completion put that in a secondary thread.

-- 
Scott McPhillips [VC++ MVP] 

0
Scott
3/21/2008 2:25:33 AM
David Wilkinson wrote:
> Z.K. wrote:
>> I was wondering if someone could tell me how to implement a couple of 
>> threads.  I have an MFC application which launches a Command line 
>> application using 4 different commandline arguments.  This works fine 
>> using CreateProcess, but I also want to update a progress bar to the 
>> amount of how long the command line application stays active.  I 
>> created a thread to update the progress bar and it works, but I can't 
>> figure out how to update the progress bar at the same time that the 
>> exernal process is active.  The program always waits until the process 
>> is complete before updating the progress bar.  Any help would be 
>> appreciated.
> 
> You need to supply more information.
> 
> How are you detecting that the command line program has finished?
> 
> And you mention a couple of threads at the beginning. But later only one.
> 

Sorry for being so vague.  What I want to do is start the command line 
application using CreateProcess which as I said works fine.  I also at 
the same time want to update a progress bar on the form.  I am just 
assuming that I need to use a thread or threads of some type and I 
definitely not an expert on using threads.  I have an idea that if I 
could start the commandline process in a thread I could just use the 
OnTimer to update the progress bar.

    Z.K.
0
nospam2791 (369)
3/22/2008 2:05:57 AM
Scott McPhillips [MVP] wrote:
> "Z.K." <nospam@nospam.net> wrote in message 
> news:ePaiLnriIHA.3512@TK2MSFTNGP03.phx.gbl...
>> I was wondering if someone could tell me how to implement a couple of 
>> threads.  I have an MFC application which launches a Command line 
>> application using 4 different commandline arguments.  This works fine 
>> using CreateProcess, but I also want to update a progress bar to the 
>> amount of how long the command line application stays active.  I 
>> created a thread to update the progress bar and it works, but I can't 
>> figure out how to update the progress bar at the same time that the 
>> exernal process is active.  The program always waits until the process 
>> is complete before updating the progress bar.  Any help would be 
>> appreciated.
> 
> 
> Apparently you have stopped your main thread from processing messages 
> while waiting for the external process to complete.  That will prevent 
> updates of the progress bar.  It will also lock up the secondary thread 
> that is attempting to update the progress bar.
> 
> The solution is: don't block the main thread, it should always return 
> soon to MFC so messages can be processed.  If you need a wait or wait 
> loop to detect external process completion put that in a secondary thread.
> 

Unfortunately, I do not know how to do that.  I was able to create a 
single thread that updates the progress bar, but I don't know how to 
really start two threads at the same time and to have one update the 
progress bar and the other to launch the command line application using 
CreateProcess.  Any ideas or an example perhaps?

   Z.K.
0
nospam2791 (369)
3/22/2008 2:08:25 AM
Z.K. wrote:
> I was wondering if someone could tell me how to implement a couple of 
> threads.  I have an MFC application which launches a Command line 
> application using 4 different commandline arguments.  This works fine using 
> CreateProcess, but I also want to update a progress bar to the amount of how 
> long the command line application stays active.  I created a thread to 
> update the progress bar and it works, but I can't figure out how to update 
> the progress bar at the same time that the exernal process is active.  The 
> program always waits until the process is complete before updating the 
> progress bar.  Any help would be appreciated.
> 
>    Z.K. 
> 
> 


Thanks for the help, but I figured it out finally.  I used 
WaitForInputIdle(ProcessInformation.hProcess,INFINITE) instead of 
WaitForSingleObject.  I thought this would do it, but I was having 
trouble figuring it out.  Anyway, it is working the way I want it to 
now.  Thanks.

   Z.K.
0
nospam2791 (369)
3/22/2008 9:02:05 AM
Reply:

Similar Artilces:

IIS 7 Default page
Hello everyone, I just installed the IIS7 web services, web site and FTP on my PC, there is a default page that comes up when I log into my web site the IIS7 welcome page, I already have a default.htlm page that I would like to use instead of the default one, how do I go about replacing the default IIS7 welcome page with my own welcome page. Thanks in advance. Getting into a whole discussion about publishing web pages is probably not what this newsgroup is all about, you're better off asking your questions over on the microsoft.public.inetserver.iis newsgroup. But the ...

IE 7 case title
We're on CRM 3.0 and just upgraded to IE 7. The title bar in IE 6 showed the ticket number of casts making it easy to reference a specific case in the task bar. IE 7 shows the GUID related to the case. Is there any way to show the ticket number instead of the GUID? Sarah The ticket number is still visible in the Window title, but it's been pushed off to the right of the CRM Case GUID. I do not know of any hacks in place to correct this... -- MD "Sarah Montgomery" wrote: > We're on CRM 3.0 and just upgraded to IE 7. The title bar in IE 6 showed the > tick...

investigate threads
hi all, how way to discover threads take a lot of CPU in an application ? i use VC 6.0 to debug. My app is running, then i move mouse over menu and take a lot of CPU. My app is also related to Paint event. and i want to find a tool intergrate into VC for debuging. It sounds like you are wanting a "profiler". There is one included with the installation of Visual C++ 6. Or, you can look for NuMega's TrueTime or Rational's Visual Quantify. "Duy Trinh" <duy.trinh@mobinex.com> wrote in message news:O4k55BTNHHA.2028@TK2MSFTNGP03.phx.gbl... > hi all, &g...

I HATE THREADS
Not really; It's just that I guess I am too stupid to figure them out. I have a communications app that has 2 threads for Send and Receive. I've worked and worked and debugged to try and get the logic right to handle closing the app and the com port logically so as not to get hung. I use PostMessage() in the threads so as not to get stuck when sending a message to the app in case is't closing down. However my current problem does not occur when closing the app but during an OnTimer() message in which case I detect that the device on the com port has stopped responding. When t...

Question for experts IE 8 on Win 7
When I have an IE 8 window open, I experience a flickering in the taskbar. This stops when I minimize the window or run the cursor over it. Have run antivirus, spyware, malware... everything's good. Should I worry? Hi, Do you have the G'Mail Taskbar notifier installed? or the Google Task bar search box installed? On Win7 you can click on the Task Bar Notification area and then choose which 'services' you want displayed on the Task Bar. (other OS versions you need to disable these items from msconfig>Startup.) Ensure you have the latest versions of Goog...

550 5.7.1 error for external mail (This system is configured to reject mail...)
Hello We are running Exchange 2003. Over the weekend we migrated our domain to a new nameserver. In the process the A records for www, *, @ were changed. The SPF record was modified slightly. All the other records, both MX and A have been kept the same. The DNS records are as follows: A: mail > 213.185.212.195 MX: 10 mail.carson-mcdowell.com 20 relay1.nevadatele.com 30 relay2.nevadatele.com SPF: v=spf1 mx ptr ?all This is the only change that we are aware of taking place over the weekend. Our email was working fine on Friday (day migration was initiated), Saturday and at least up unt...

show discussion thread for mailinglists
Hello, I use outlook as my mailclient and so I also get some mailinglist (i.e. DIRECTXDEV@DISCUSS.MICROSOFT.COM). My problem is that using outlook (2003) it is quite hard to follow the discussion. Since it is kind of hard to see what mail is a reply to what. In outlook express it works just fine you have some kind of treeview with indents that clearly show the discussion thread. Only it seems like outlook is not capable of doing that. Or is there a way. Maybe a plugin or something .... ? ...

Threading and event driven
hi can any one tell some web side ,on which i can get code for event driven and threading programming in MFC AND VC++. Arbind All programs in MFC are event-driven. There are some examples of multithreaded programs on my MVP Tips site, including my process class and two essays on multithreading. joe On Sat, 30 Aug 2003 09:53:37 +0530, "Arbind" <arbindb_tech@rediffmail.com> wrote: >hi can any one tell some web side ,on which i can get code for event driven >and threading programming in MFC AND VC++. > > >Arbind > Joseph M. Newcomer [MVP] email: newc...

Save As with FP2003 in Windows 7
Has anyone solved this one yet? I've googled around a lot, found a lot of common misery, and a few assertions of "works here!" Not helpful. Looking for actual clues. Thanks... Karl -- [.NET: It's About Trust!] What problem? What version of Windows 7 (Beta, RC or Retail)? Beta and RC often hung when using the save or save as menu in many programs (not just FrontPage, but never Notepad), but there are no problems (for me) in the retail version. -- Ron Symonds Microsoft MVP (Expression Web) http://www.rxs-enterprises.org/fp Reply only to gr...

How to make a class member function a thread ??
Hi, I have a class say, derived from CDialog.. I have a member function which i want to start as a thread.. I need to use APIs like CreateThread or AfxBeginThread to start the thread, but how to make a member function as a thread.. I can not derive a whole class from CWinThread and make a member function of that.. that is my limitation.. So, how can we make a member function of a simple class as a thread ? I can declare the member function as static to avoid ambiguity.. Regards, Jigar Mehta Jigar, I might be misunderstanding you completely, but you have already answered your own ...

Test Mail...Please Ignore #7
Testing NNTP Client, Please ignore message Thanks ...

Outlook 2003 under Windows 7
Are there any problems running Outlook 2003 under Windows 7? Minor problems are reported - zip attachments won't open & the compose window is grouped with Word on the task bar. We're also seeing some reports of Outlook hanging but I'm not sure that is related specifically to Win7. See http://www.slipstick.com/emo/2010/up100114.htm#1 for the zip fix. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by email: mailto:dailytips-subscribe-request@lists...

550 5.7.1 Unable to relay for user@domain.com #2
I'm running Exchange 2003 on server 2003 sp1 and im getting relaying errors from external domains. I can send to internal and external users ok, but if someone from an external domain (gmail.com, yahoo.com, etc) try to send me a message i get this error: Technical details of permanent failure: PERM_FAILURE: SMTP Error (state 9): 550 5.7.1 Unable to relay for user@domain.com I checked my mx record and everything seems to be ok. ive been reading up on relaying, and from what i understand, i shouldnt have to enable relaying unless i want an external user in domain1 to send mail through my e...

Clip zooms in Windows 7
With OneNote 2007 and a new laptop running Windows 7 Clip (screen clipping) now Zooms the underlying window we are clipping from. Is there a way to turn this zoom off? On Sun, 25 Apr 2010 15:19:01 -0700, Julie <Julie@discussions.microsoft.com> wrote: >With OneNote 2007 and a new laptop running Windows 7 Clip (screen clipping) >now Zooms the underlying window we are clipping from. Is there a way to turn >this zoom off? Assuming "Windows 7 Clip" is a third-party program (I've not heard of it as a part of Windows 7), and the problem only manifests ...

read receipts #7
Hi, Does anyone know how to setup exchange 2003 so that it allows a requested read receipts to be returned to a requesting external company. I know it can be done from within the exchange organization going outwards but how can you set this up so it allows a read receipt to be returned to a company outside your organizagtion? i have posted this before but unfortunately I am still wondering if this is possible. Thanks RR's are a client action, not a server. What's going on? "Paul" <Paul@discussions.microsoft.com> wrote in message news:733B5639-3B96-46F3-8C9...

Add-ins #7
I received a new add-in for joining. I followed the instructions but don't know how to use it now? This was the add-in for selecting worksheets. Rita -- Reetz73 ------------------------------------------------------------------------ Reetz73's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=25070 View this thread: http://www.excelforum.com/showthread.php?threadid=385883 ...

Charts #7
I have just produced a chart in excel and as soon as I click on the spreadsheet again the chart area turns grey and I can't see the content of the chart. Does anyone know how to switch back to regular setting? Any help is much appreciated As answered in microsoft.public.excel.charting: Choose Tools>Options On the View tab, under Objects, select "Show All" Click OK OlofCitiFIG wrote: > I have just produced a chart in excel and as soon as I click on the > spreadsheet again the chart area turns grey and I can't see the content of > the chart. Does anyone know ...

No Win 7 Mouse Wheel Scrolling
I'm having a problem scrolling table rows in Access 2007 and 2003 with the mouse wheel. If I scroll the wheel about as fast as possible it might scroll one row in table view then nothing. Otherwise nothing scrolls with normal wheel speed scrolling. Mouse wheel scrolling is normal in database windows for tables, forms, etc. and in modules. Wheel scroling is normal in other programs. I have tried two mice(sp?), both MS wireless type, but different models. Built some new datagrid views that I read are designed to allow wheel scrolling. Any registry setting, etc. I can che...

multi-threading issue...
I am writing a class for a status window, but I want this status window to be in a completely separate thread so it won't interfere with anything in the main thread or add any overhead, or be slowed down by the main thread since it does stuff on a timer, and I've seen similar windows become really slow because the timer message is such low priority. I figured I would solve the problem by having the status window live in its own thread. So my basic design is: class CStatusWnd : public CObject { }; CStatusWnd is not actually going to wrap the m_hWnd of the object in the sense th...

CAsyncSocket::Receive and CAsyncSocket's threading...
Hi again, 1. Is CAsyncSocket::Receive a blocking function? 2. How is the IO Strategy for MFC's CAsyncSocket? 1 thread to do all stuff? Thanks again. pixelmana wrote: > Hi again, > 1. Is CAsyncSocket::Receive a blocking function? > 2. How is the IO Strategy for MFC's CAsyncSocket? 1 thread to do all stuff? > Thanks again. 1. No. "Async" means non-blocking. 2. CAsyncSocket sends you notifiction messages via the Windows message queue. These messages are just like button and mouse messages. CAsyncSocket turns them into calls to your derived class virtual fu...

Windows 7 and office upgrade
I have just purchased a new laptop, I have works 9 with an office proffesional upgrade. However after I installed works and then attempted to install the upgrade I kept getting an error stating that it could not find an upgradable product. Works 9 is listed on the packaging as an upgradable product and I previously installed on Vista. is thi sperhaps a windows 7 problem? You need to update Works http://www.microsoft.com/downloads/details.aspx?FamilyId=04446BAB-F439-4DB8-856B-2DE7234F22A0&displaylang=en "Russell" <Russell@discussions.microsoft.com> wrote in me...

Singletons and threads
I have an application where different user-interface threads need to access common resources like event logs, configuration data, etc. I have a successful system where all the helper classes are constructed in my CWinApp main class. Pointers to these are made available through get functions like ((CMyApp *)AfxGetApp())->GetPointer(). (Yes, I know there are "proper" ways of casting, but I started this project years ago when I didn't know better!) Now it is time to clean up the project and I thought that singletons would be the appropriate mechanism. The literature I ...

Start background thread when a UI button is clicked, and Update UI button from background thread
I was asked these questions during a technical interview: 1) When the user clicks on a button on the form and that invokes a lot of heavy-duty calculations, what would you do? My answer: I would use "BeginInvoke" to start a background worker thread to do the heavy-duty calculations, in order to avoid blocking the main UI thread. Then he asked, "What does 'BeginInvoke' do"? I said it was a .NET pattern to start a background thread from a UI thread. Did I get it right? 2) Why can't you simply update a button on the UI thread from a background ...

Newbie: Calling a function and thread safety
Hi, Any local classes and member variables I create within my thread class are thread-safe right? But, I want to call some "utility functions" contained within separate header/cpp files that are not within any class and can be called from several threads. eg utility.h int plus(int *p1, int *p2); utility.cpp int plus(int *p1, int *p2) { return(*p1+*p2); } What must I do to ensure thread safety? Thanks Harry wrote: > int plus(int *p1, int *p2) > { > return(*p1+*p2); > } > > What must I do to ensure thread safety? This function is thread-safe. --...

Great Plains 7.5 eCommerce Error...
Source: Unrecognized CLSID Number: -2147191504 Description: CBDXCustomerMapping::Save - Error while attempting to save properties. Native Description: All of the required fields are not set. this is from event viewer...any ideas where to start looking? ...