Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Multithreading and Event handling

Multithreading and Event handling

Scheduled Pinned Locked Moved Visual Basic
data-structureshelplearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brynn
    wrote on last edited by
    #1

    I have a problem, I need to run a series of little tasks. There are only about 4 types of task but they can be run against a number of databases. The exact number of instances of each task are unknown until run time. I could run all these tasks sequntially but this may take sometime and one or more may fail or timeout extending the runtime to collect all the data. So the obvious thing is to multithread, dynamically creating the threads and holding them in an array or collection. Most of this seems fairly easy, but the main problem I have is with handling any events e.g. successful termination. I can declare events for the class this is not a problem but to actually handle the event I have to specify a SUB to handle each specific instance .e.g. Sub TermEventHandler (ByVal intResult as Integer) Handles specific_instance.TermEvent This is of course impossible as the instance does not exist at compile time. What I need is a way of having just one SUB to handle all instances of a particular thread types TermEvent. I'm sure there must be a sensible way of doing this, but being a relative newbie to this I can't see it. I hope I have explained my problem in terms people can understand. If anyone could suggest a way out of this I would be grateful. Thanks

    H 1 Reply Last reply
    0
    • B Brynn

      I have a problem, I need to run a series of little tasks. There are only about 4 types of task but they can be run against a number of databases. The exact number of instances of each task are unknown until run time. I could run all these tasks sequntially but this may take sometime and one or more may fail or timeout extending the runtime to collect all the data. So the obvious thing is to multithread, dynamically creating the threads and holding them in an array or collection. Most of this seems fairly easy, but the main problem I have is with handling any events e.g. successful termination. I can declare events for the class this is not a problem but to actually handle the event I have to specify a SUB to handle each specific instance .e.g. Sub TermEventHandler (ByVal intResult as Integer) Handles specific_instance.TermEvent This is of course impossible as the instance does not exist at compile time. What I need is a way of having just one SUB to handle all instances of a particular thread types TermEvent. I'm sure there must be a sensible way of doing this, but being a relative newbie to this I can't see it. I hope I have explained my problem in terms people can understand. If anyone could suggest a way out of this I would be grateful. Thanks

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      What i understood is that you want to create a different sub to handle each thread's events... if this is true.. I just ask why ? i think one handler is enough but you need to make some kind of synchronization search msdn for critical sections , mutex , etc.

      B 1 Reply Last reply
      0
      • H Hesham Amin

        What i understood is that you want to create a different sub to handle each thread's events... if this is true.. I just ask why ? i think one handler is enough but you need to make some kind of synchronization search msdn for critical sections , mutex , etc.

        B Offline
        B Offline
        Brynn
        wrote on last edited by
        #3

        Thanks for the reply, maybe I wasnt too clear on my original statement. Its not that I want to handle each event seperately, it was that, I did not know how 1) make a sub handle more than one event and 2) how you do this when creating a thread from scratch. As it happens I found some thing on another site last night that showed me all I needed, I now understand a little more about dynamically creating objects and hooking things up to them etc. I did say that I was a newbie to all this:-D. I'll include what I found just in case anyone else is interested 1) you can say Sub TermEventHandler (ByVal intResult as Integer) Handles specific_instance.TermEvent anotherinstance.Termevent ... 2) To hook up the event dynamically AddHandler specific_instance.TermEvent, Addressof TermEventHandler

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups