threading problem while creating COM objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tristan Ludowyk

    #1

    threading problem while creating COM objects

    Hi,

    In my application I have a worker thread which goes and sends faxes using
    winXPs FAXCOMEXLib API. When a fax is complete or fails, an event is
    triggered. In this handler I save the result and remove the fax from my
    list of faxes being sent. However before this i must make sure my worker
    thread is not currently adding new faxes to the queue.

    My solution is that the event handler signals the worker thread to sleep,
    and the worker thread stops what it is doing and enters an idle loop
    (sleeping for a few seconds then seeing if it can start again). Once the
    worker thread is sleeping, the aforementioned event handler continues to
    remove the completed fax from the list i keep and we make sure we don't have
    2 threads access the list concurrently.

    However this is causing problems because as part of sending a fax I have to
    create a FAXCOMEXLib.Fax DocumentClass object (a COM object). What I have
    found is that the constructor blocks if the event handler above is running.
    And since the event handler is waiting until the other thread constructs the
    object and can fall into the idle loop a dead lock occurs.

    This seems to me like a problem with message pumping. I have fixed this
    before in pre-.NET applications by running my own message pump until
    execution can continue. How would one do this in .NET, or is it even
    possible?

    Thanks,
    Tristan.


  • Tristan Ludowyk

    #2
    Re: threading problem while creating COM objects

    System.Windows. Forms.Applicati on.DoEvents() was what i was looking for...

    "Tristan Ludowyk" <tristan00au_AT _yahoo_DOT_NOSP AM_com> wrote in message
    news:uYMI8kC3EH A.3504@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi,
    >
    > In my application I have a worker thread which goes and sends faxes using
    > winXPs FAXCOMEXLib API. When a fax is complete or fails, an event is
    > triggered. In this handler I save the result and remove the fax from my
    > list of faxes being sent. However before this i must make sure my worker
    > thread is not currently adding new faxes to the queue.
    >
    > My solution is that the event handler signals the worker thread to sleep,
    > and the worker thread stops what it is doing and enters an idle loop
    > (sleeping for a few seconds then seeing if it can start again). Once the
    > worker thread is sleeping, the aforementioned event handler continues to
    > remove the completed fax from the list i keep and we make sure we don't
    > have 2 threads access the list concurrently.
    >
    > However this is causing problems because as part of sending a fax I have
    > to create a FAXCOMEXLib.Fax DocumentClass object (a COM object). What I
    > have found is that the constructor blocks if the event handler above is
    > running. And since the event handler is waiting until the other thread
    > constructs the object and can fall into the idle loop a dead lock occurs.
    >
    > This seems to me like a problem with message pumping. I have fixed this
    > before in pre-.NET applications by running my own message pump until
    > execution can continue. How would one do this in .NET, or is it even
    > possible?
    >
    > Thanks,
    > Tristan.
    >[/color]


    Comment

    Working...