Handling API events in a background thread RRS feed

  • Question

  • Hello,

    I am in the planning stages for developing a VB.Net class (I am using VS 2008) that is to obtain data via an API provided by a COM object (AxInterop.TWSLib) making requests to an Internet server. The API provides data via events. The class should do its work on a separate thread; it takes several seconds (sometimes up to ~10) to collect the desired data. One should be able to instantiate several instances of the class in order to collect data in parallel. The class would be given a reference to the TWSLib object when its constructor is called, as well as several parameters. There needs to be a way for the class to provide results, preferably in the form of a generic list.

    I have succeeded creating multithreads using the backgroundworker approach. From what I have read, though, that does not appear to be the appropriate approach when the background thread is supposed to wait for events to handle. I have not tackled more advanced multithreading approaches. Studying VS 2008 documentation on Threading, ThreadPool, delegates, etc. has not yet given me an idea how to design a class that handles those API events asynchonrously. Could you please point me into a fruitful direction - what would be the general approach, what do I need to study, is there sample code somewhere?

    Or might you recommend writing a separate application instead of that class, running several of them in parallel, and communicating via WCF? I have done something similar, but it seems awkward.

    My OS is Win 7 Pro.


    Thursday, April 7, 2011 5:25 AM


  • You don't wait for it. The different tasks given to BackGroundWorker will occur on different threads, not a dedicated back ground thread.
    • Proposed as answer by eryang Monday, April 11, 2011 7:09 AM
    • Marked as answer by eryang Tuesday, April 19, 2011 2:17 AM
    Friday, April 8, 2011 4:51 PM

All replies