NibblyPig
NibblyPig

Reputation: 52922

How do I run asynchronous code in asp.net mvc 2?

I tried this:

    BackgroundWorker bw = new BackgroundWorker();

    bw.DoWork += (o, e) =>
    {
        SendConfEmail();
    };

   bw.RunWorkerAsync();

but it didn't work. SendConfEmail takes a while to run. I guess it's because BackgroundWorker is designed for winforms not webforms.

Any ideas how I can solve the problem?

Upvotes: 0

Views: 153

Answers (2)

NibblyPig
NibblyPig

Reputation: 52922

I solved it eventually by using an AsyncCallback object.

A centralised mail server solution would be ideal, but this project was a time critical proof of concept that had to be completed in just five days.

Upvotes: 0

user1228
user1228

Reputation:

Waiting for a background thread to get queued up on the CPU from within a request is going to be near pointless. You should probably queue your emails from all threads and service them from a separate process, or from within a dedicated thread spawned, say, within global.asax.

Upvotes: 1

Related Questions