Threading

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
9/1/2008 3:50:54 PM
Gravatar
Total Posts 33

Threading

Hi Joe,

I noticed you are using Threading in sending newsletters, could you please elaborate abit more on how you use threads in ASP.NET?

Cheers

James

9/1/2008 4:14:41 PM
Gravatar
Total Posts 18439

Re: Threading

Hi James,

I talk about using threads and specifically about why I needed it for sending newsletters in this article under developer docs:

Using the Task Framework

You can use the LetterSendTask as an example for implementing your own task that can run on a background thread. The key thing is to be aware that your thread can be killed if the app pool is recycled while it is running.

Hope it helps,

Joe

9/1/2008 4:22:17 PM
Gravatar
Total Posts 33

Re: Threading

Hi Joe,

Thanks for the info, do you kick off a thread by the code-behind or with an extra layer of c# code?

Cheers

James

9/1/2008 4:29:24 PM
Gravatar
Total Posts 18439

Re: Threading

If you look at the StartTask method in LetterSendTask.cs you'll see the code for starting a new thread is very simple, just one line really:

if (!ThreadPool.QueueUserWorkItem(new WaitCallback(RunTaskOnNewThread), this))
{
throw new Exception("Couldn't queue the task on a new thread.");
}

You pass a method with a signature that takes one object into the contrustor of the WaitCallback object and pass it to ThreadPool.QueueUserWorkerItem. In the case of the task, the object it passes is itself "this"

private static void RunTaskOnNewThread(object oTask)
{
if (oTask == null) return;
LetterSendTask task = (LetterSendTask)oTask;

log.Info("deserialized LetterSendTask task");

// give a little time to make sure the taskqueue was updated after spawning the thread
Thread.Sleep(10000); // 10 seconds

task.RunTask();

log.Info("started LetterSendTask task");

}

Hope it helps,

Joe

9/1/2008 4:48:18 PM
Gravatar
Total Posts 33

Re: Threading

Thanks Joe.

9/8/2008 7:31:59 AM
Gravatar
Total Posts 18439

Re: Threading

A really good blog post about ASP.NET threading came through my google reader today.

http://blogs.msdn.com/benchr/archive/2008/09/03/does-asp-net-magically-handle-thread-safety-for-you.aspx

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.