Solved

File Download Tracking

Posted on 2003-10-24
9
191 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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Awsome Dan....exactly what I was looking for.
0
 

Author Comment

by:SGyves
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

728 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

10 Experts available now in Live!

Get 1:1 Help Now