Results 1 to 4 of 4

Thread: multiupload thread queue

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    10

    multiupload thread queue

    Hi, I'm just a newbie and try to do mutltiupload to a php script.

    My app talk to an external app
    This external app put some files in a backup directory and send to my app a signal alet

    My app receive this signal (a specific message) via the Overrides Sub WndProc()

    When I receive the message, I know that there is a file to upload to my webserver.
    Code:
    Sub WndProc()
    
    ...... ThreadPool.QueueUserWorkItem(AddressOf AutoUpload, upldData) ......
    end sub

    Code:
    delegate D_AutoUpload(dt as object)
    sub AutoUpload(dt as object)
    
    ....... StatusCode = upload(filepath, UrlWebsite) if statuscode = "OK" then
    deleteFile(filepath)
    end if ......
    end sub

    Code:
    Function upload(filepath as string, UrlWebsite as string)
    
    ....... .......(upload & update a progressBar) ....... Return statusCode
    end sub
    A upload maybe a little bit longer and sometimes I have to upload another one before my previous file is completed.
    Because I receive several signals alert in 5 or 10sec and a upload is about 10sec to 2mins by file.
    I must upload all files one by one in the correct order.
    I would like to wait the previous upload accomplished before to upload the next one.
    I think, I have to use thread, queue, maybe threadpool but don't have any Idea.

    If someone could tell me how to do, It will be very appreciated.
    Thanks in advance
    Isa

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: multiupload thread queue

    Well, what you could do is instead of having your overriden WndProc do the uploads itself, you add it to a list and have a separate thread enumerate this list one by one and upload each file.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    10

    Re: multiupload thread queue

    Hi Niya,

    Thanks fer answer.

    I need to upload in real time.
    Each time a file is placed in the folder, I have to upload this file to my webserver.
    I use WndProc to trigger my upload.

    When a file is placed on the backup directory, immediatly, my application receive a message via the WndProc.
    From WndProc I call my function (AutoUpload).

    And sometimes I receive 3 or more messages (3 files or more in the backup directory) in few seconds.
    I can not upload all files at the same time. Only 1 by 1. How to do. I think I have to declare a queue or something like that. (enqueue, dequeue)
    But I don't know exactly how to do the nexts steps with the threads.

    Isa

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: multiupload thread queue

    If you can't upload simultaneously then it really doesn't make any sense to create a new thread for each file at all. It would be much easier all round if you had one upload thread accessing a list of filenames. Your update process adds new files to the list. The upload thread can run on a loop, checking the list, uploading any file in the list then removing it from the list. If after this there remain items on the list upload the next, if not sleep for whatever period is appropriate.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width