DownloadQueue [modified]
-
Hi guys, I am not sure if this should be VB specific or more design but i'm a bit stuck with a dll i try to write. This dll should take care of communication with our server (tcp) and download files. Then this dll can be used by various host applications that need connection with our infrastructure. Now i want to build a download queue which in the back is downloaded ( backgroundworker ) and where i can add downloads selected by the app (it's about music and video files). This "queue" needs to be exposed to the host application so they can see the queue and what is happening.. However.. first i thought of doing this using our database ( we use sqlite for the communications DLL).. however.. sqlite and multithreading don't get along AT ALL.. so this locked the database giving all sorts of evil errors (and worse.. sometimes blocked the TCP Socket from writing data into the local database which takes priority over the downloads Then i wanted to do this using a datatable but this too gives all sort of strange issues which just seem to send me in a loop (exposing the queue using a dataview.. the connected datagridview doesn't refresh as it should, when row is selected that is downloaded and then gets removed from the view we get "isnull" errors etc, etc, etc) Now my ideas are out and i turn here: What is the best way to build a download queue which: Needs to be able to prioritized needs to be visualised like our background thread is using it (so with the priority in place) Where multiple threads can add / remove downloads from it.. Can anyone point me in a right direction ? Many thanks !
Do Or Don't, there is no "try catch ex as exception end try"
modified on Sunday, December 28, 2008 9:42 AM
-
Hi guys, I am not sure if this should be VB specific or more design but i'm a bit stuck with a dll i try to write. This dll should take care of communication with our server (tcp) and download files. Then this dll can be used by various host applications that need connection with our infrastructure. Now i want to build a download queue which in the back is downloaded ( backgroundworker ) and where i can add downloads selected by the app (it's about music and video files). This "queue" needs to be exposed to the host application so they can see the queue and what is happening.. However.. first i thought of doing this using our database ( we use sqlite for the communications DLL).. however.. sqlite and multithreading don't get along AT ALL.. so this locked the database giving all sorts of evil errors (and worse.. sometimes blocked the TCP Socket from writing data into the local database which takes priority over the downloads Then i wanted to do this using a datatable but this too gives all sort of strange issues which just seem to send me in a loop (exposing the queue using a dataview.. the connected datagridview doesn't refresh as it should, when row is selected that is downloaded and then gets removed from the view we get "isnull" errors etc, etc, etc) Now my ideas are out and i turn here: What is the best way to build a download queue which: Needs to be able to prioritized needs to be visualised like our background thread is using it (so with the priority in place) Where multiple threads can add / remove downloads from it.. Can anyone point me in a right direction ? Many thanks !
Do Or Don't, there is no "try catch ex as exception end try"
modified on Sunday, December 28, 2008 9:42 AM
It sounds like you need a priority queue and a way to retrieve some status information from it. It also sounds like you have the priority queue in place. Use locking for queue access and modification. I'm a C# developer and don't know the VB.NET syntax, but in C# there's the
lock
keyword that can be used to lock a section of code for execution by a single thread. It's pretty simple and the most common technique is to create a locker object that is locked in every place the queue will be touched. Depending on your needs you may want to go with a subscriber model to provide information to other applications. With it you would have queue modification events that other applications 'subscribe' to and they would implement an event handler that will give them an EventArgs object with information about the event (ItemAdded, ItemRemoved, ItemUpdated, ItemProcessed, etc.). Or, perhaps you want to go with a by-request model in which you have methods that return a status object only when invoked. Using .NET Remoting may be useful if it is a Client-Server architecture as the TCP/IP communication is already handled for you and it defaults to using a Singleton, where one instance of the priority queue will exist on the server and clients can interact with that instance remotely.Keep It Simple Stupid! (KISS)