Execute a block of database querys

Posted by Nightmare on Stack Overflow See other posts from Stack Overflow or by Nightmare
Published on 2012-11-28T11:02:19Z Indexed on 2012/11/28 11:03 UTC
Read the original article Hit count: 220

I have the following task to complete:

In my program a have a block of database querys or questions. I want to execute these questions and wait for the result of all questions or catch an error if one question fails!

My Question object looks like this (simplified):

public class DbQuestion(String sql)
{
    [...]
}

[...]

//The answer is just a holder for custom data...
public void SetAnswer(DbAnswer answer)
{
    //Store the answer in the question and fire a event to the listeners
    this.OnAnswered(EventArgs.Empty);
}

[...]

public void SetError()
{
    //Signal an Error in this query!
    this.OnError(EventArgs.Empty);
}

So every question fired to the database has a listener that waits for the parsed result.

Now I want to fire some questions asynchronous to the database (max. 5 or so) and fire an event with the data from all questions or an error if only one question throws one!

Which is the best or a good way to accomplish this task? Can I really execute more then one question parallel and stop all my work when one question throws an error?

I think I need some inspiration on this...

Just a note: I´m working with .NET framework 2.0

© Stack Overflow or respective owner

Related posts about c#

Related posts about database