How to sync this asynch process ?

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

    #1

    How to sync this asynch process ?

    Hello,

    I'm inserting a new row in a Access database containing an
    "AutoIncrem ent" column.
    The autoincrement value is set by the database once the update occurs.
    The only way to get this value is through an event delegate.

    My question is inside the comments :

    ....
    ....
    ....

    // Call to a function raising a delegated event which attributes
    // a value to the lProductId variable
    ret = MyFuncReturning ResultThroughDe legate()

    // How to stop here until the lProductId is newly affected
    // as the previous call returns immediatly even if the delegate
    // is not yet reached.
    // (I want to wait the delegate to make its job)
    ....
    ....
    ....

    I would think about a binary semaphore synch mechanism (is it the good
    mechanism to choose ?) but i'm not sure how (which API) should be used
    in C# to implement it.

    Any ideas ?


    Regards,
    Cybertof.





  • Bret Mulvey [MS]

    #2
    Re: How to sync this asynch process ?

    You've got it right, assuming the async call cannot be avoided. Just create
    a System.Threadin g.ManualResetEv ent before making the async call, and then
    do WaitOne() on the ManualResetEven t. In the delegate, do Set() on the
    ManualResetEven t and your waiting code will continue.

    If you have any other non-CPU-bound work you might be doing, such as disk
    I/O, setting up another DB call, etc., do it while you're waiting for the
    callback before you call WaitOne(). That's otherwise wasted time.

    "Cybertof" <cybertof2003no spam@gmx.net> wrote in message
    news:MPG.1a188b 056f7725939896c e@msnews.micros oft.com...[color=blue]
    > Hello,
    >
    > I'm inserting a new row in a Access database containing an
    > "AutoIncrem ent" column.
    > The autoincrement value is set by the database once the update occurs.
    > The only way to get this value is through an event delegate.
    >
    > My question is inside the comments :
    >
    > ...
    > ...
    > ...
    >
    > // Call to a function raising a delegated event which attributes
    > // a value to the lProductId variable
    > ret = MyFuncReturning ResultThroughDe legate()
    >
    > // How to stop here until the lProductId is newly affected
    > // as the previous call returns immediatly even if the delegate
    > // is not yet reached.
    > // (I want to wait the delegate to make its job)
    > ...
    > ...
    > ...
    >
    > I would think about a binary semaphore synch mechanism (is it the good
    > mechanism to choose ?) but i'm not sure how (which API) should be used
    > in C# to implement it.
    >
    > Any ideas ?
    >
    >
    > Regards,
    > Cybertof.
    >
    >
    >
    >
    >[/color]


    Comment

    Working...