Solved

File Download Tracking

Posted on 2003-10-24
9
197 Views
Last Modified: 2013-11-20
I have a possible solution for a problem and I wanted to bounce it off the experts. I need to keep track of the file downloads that my program starts. Here is the way that it manages them. The document is told that there is a download to do, and it forms a DCCConnection object which basically uses a CSocket object inside of a worker thread to handle the download. The worker thread creates the socket, connects, and loops to recieve bytes until it is complete or it gets cut off. I would like the document to be able keep track of all the downloads and report the status as well. Right now (I don't even know why it works but it does) it creates the DCCConnection in a function starts the thread, and then the reference goes out of scope, however, the download continues successfully. So there is this unreferenced worker thread out there doing its own thing.

Here is my planned idea. I think that it may be a good idea to keep a CTYpedPtrList of thread pointers (representing the worker threads) and have the thread send a message to the main thread with a COMPLETE or FAIL parameter and a thread ID to remove from the list. The thing is...I need the document to get the message. I would appreciate any ideas on how to best achieve such a structure. THank you all for your help.
0
Comment
Question by:SGyves
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9616241
Good idea to keep track of objects/threads you create (you may need to terminate them if you want to close your app before the thread finishes).

Documents have a MESSAGE_MAP handler however I have not tried posting a message cross threads, maybe it wont work (memory adresses in different threads may not match).

So maybe better to give the thread the HWND of the main app window and let it post a message to that.
Is it SDI?  Yes - then only one doc, NO - then you will need to supply more info to the thread as to which is the doc the main window should instruct a thread has posted it a message.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9616373
If this is related to the progress dialog question then it is possible to create a thread that does have a user interface so you can display the progress directly from the thread.  
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9616424
Yet another possibility is to have a separate (dlg based) app that handles the download and displays progress.  You can spawn a thread with CreateProcess passing the required download info as part of the startup parameters. If the HWND of the main app is also passed then it could use the normal ::PostMessage(...) to inform the main app of success/failure.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 49

Expert Comment

by:DanRollins
ID: 9618256
There is no need to create a CThread-derived object or a pointer to it.   However, there is usually some time of object associated with the thread.  If this is the same project youv'e been working on, then you alteady haave a CDocument-derived object associated with it.  All CDocuments are easy to locate because MFC keeps track of them for you.  If you want to make a separate list, then that's possible too, but probably not needed.

-- Dan
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9618900
I added my suggestion to this thread:
http://oldlook.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20776592.html

and now I see that you did almost same design. So, your idea is right, two corrections are:

1) post messages to main frame and access CDocument from it
2) Use modal dialog which shows all threads in current state. When dialog is not active, show some indication like icon on progress bar. Instead of minimizing dialog is closed.

See full answer it your previous question, I hope it solves your problems.
0
 

Author Comment

by:SGyves
ID: 9620197
Dan ...it is the same project...however there are going to be many downloads per open document. So I think I will need a list to keep track.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 9620319
You should make some sort of Download object and maintain a list of them in the CDocument.   This object could handle all facets of the download operation, including controlling the modeless dialog and its progressbar and watching to see if the user canceled, etc.

The actual form the list is unimportant.  First pass, I'd just make a simple fixed-length array.  But any of the collection classes such as CPtrArray would work.

As always, the main U/I thread would do all of the window handling.  Any code running on a worker thread should just update status variables in its associated object.  Your timer handler in the main window would cycle through all CDocuments and cycle through all CDownloadObjects to see what, if any screen activity needed to be handled, which ones need to be closed, which progress bars are out of date, etc.

-- Dan
0
 

Author Comment

by:SGyves
ID: 9620487
Awsome Dan....exactly what I was looking for.
0
 

Author Comment

by:SGyves
ID: 9621793
Really....thank you for all your input everyone..I am really beginning to see how this all works. As far as threads go. I appreciate you all putting up with my questions and always being so good about following up. Dan...I am going to give you the points here..and Alex...I will give you the points in the other question. Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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