Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 544535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:39:54+00:00 2026-05-13T10:39:54+00:00

In a previous question I asked how to improve a bit of code. It

  • 0

In a previous question I asked how to improve a bit of code. It was said that I should move it to a new thread. I’d never thought about it before so it seems like a great idea to me. So this morning I went ahead and reused a bit of code I already have for processing emails and updated the way I handle image uploads into my site.

So is this a good way to start a new thread and process the images? Is there even a need to lock it like I am?

private static object dummy = new object();

public static void Save(int nProjId, byte[] bData)
{
    var worker = new ThreadStart(() => ProcessImage(nProjId,bData));
    var thread = new Thread(worker);
    thread.Start();
}

private static void ProcessImage(int nProjId, byte[] bData)
{
    lock (dummy)
    {
        try
        {
            byte[] xlargeImage = Thumbs.ResizeImageFile(bData, 700);
            byte[] largeImage = Thumbs.ResizeImageFile(bData, 500);
            //improved based on previous question to use the already reduced image
            byte[] mediumImage = Thumbs.ResizeImageFile(xlargeImage, 200);
            byte[] smallImage = Thumbs.ResizeImageFile(xlargeImage, 100);

            //existing code to actually save the images
            MyGlobals.GetDataAccessComponent().File_Save(
                ConfigurationManager.ConnectionStrings["ImgStore"], 
                nProjId,
                xlargeImage,
                largeImage,
                mediumImage,
                smallImage);
        }
        catch (Exception)
        {
            //ToDo: add error handleing
            { }
            throw;
        }
    }
}

Oh and the images now upload and process nearly instantly (locally) so it’s a HUGE help so far. I just want to make sure it’s the best way to do it. Oh and I’m using a dual core machine running Server 2008 with 6gb or ram, so I have a little wiggle room to make it faster or use more threads.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:39:54+00:00Added an answer on May 13, 2026 at 10:39 am

    I would suggest using a ThreadPool class, specifically because it will re-use a thread for you rather than you creating a new thread each time, which is a little bit more intensive.

    Check out the QueueUserWorkItem method.

    Also if you are not using a static resource to write to (I am not sure what exactly File_Save does) I dont think there is a need for your lock. However if you are using a static resource then you should lock just the code that is using it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A previous question I asked indicated that this was 64 bit (8 byte) double-precision
So in a previous question I asked about implementing a generic interface with a
In a previous question I asked about how to group XML elements logically, and
This stems from a previous question I asked - about a write conflict with
This is a follow up question to a previous question I asked about calculating
Unit testing Abstract classes in Groovy I asked a question previous about unit testing
Continuing a previous question I asked here , I now need to move to
In my previous question I asked about storing the result of a query in
This question is a folo to a previous question I asked about how to
Ok, so I am trying to improve on my previous question about dynamic CSS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.