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 6742605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:51:48+00:00 2026-05-26T11:51:48+00:00

I have a simple Windows service, which runs only once per day. It performs

  • 0

I have a simple Windows service, which runs only once per day. It performs some queries in database, generates appropriate html content (tables, divs, …) and sends it in body of an e-mail to multiple recipients.

The body of the e-mail is created like this:

private static string GenerateBody()
{
    using (var stringWriter = new StringWriter())
    using (var htmlWriter = new HtmlTextWriter(stringWriter))
    {
        htmlWriter.RenderBeginTag("html");
        htmlWriter.RenderBeginTag(HtmlTextWriterTag.Head);
        htmlWriter.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
        htmlWriter.RenderEndTag();
        htmlWriter.RenderBeginTag("body");

        htmlWriter.Write(
            new StringBuilder()
                .Append(OverviewParagraph.GenerateHTMLContent())
                .Append(PackageWeightParagraph.GenerateHTMLContent())
                .Append(BoxWeightParagraph.GenerateHTMLContent())
                .Append(CodeQualityParagraph.GenerateHTMLContent())
                .Append(ChecksParagraph.GenerateHTMLContent())
                .ToString()
        );

        htmlWriter.RenderEndTag();
        htmlWriter.RenderEndTag();

        return stringWriter.ToString();
    }
}

All the GenerateHTMLContent methods are pretty much the same – they execute a query in my database, build an HTML table with the help of a HTMLTextWriter and return the table as a string.

Can this code be improved with the use of multithreading or maybe async-await pattern? The code in question is where I append lines to the StringBuilder object.

EDIT: I asked the question because I never worked with multithreading before, just wanted to know if it is possible. Besides, the program runs fast enough now.

  • 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-26T11:51:49+00:00Added an answer on May 26, 2026 at 11:51 am
    StringBuilder sb = new StringBuilder();
    Parallel.Invoke(
        () => { var s = OverviewParagraph.GenerateHTMLContent(); lock (sb) sb.Append(s); },
        () => { var s = PackageWeightParagraph.GenerateHTMLContent(); lock (sb) sb.Append(s); },
        () => { var s = BoxWeightParagraph.GenerateHTMLContent(); lock (sb) sb.Append(s); },
        () => { var s = CodeQualityParagraph.GenerateHTMLContent(); lock (sb) sb.Append(s); },
        () => { var s = CodeQualityParagraph.GenerateHTMLContent(); lock (sb) sb.Append(s); }
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple .NET application which runs as Windows Service. Say it has
i've created simple windows service which gets some xml information once in a hour.
I have created a simple windows service that periodically checks a remote database via
I have a simple class which sets up NserviceBus for a legacy windows service.
We have a simple WCF (on .NET 4.0) Service which uses Windows authentication and
I have a simple WCF service which accept some data (wsHttpBiding) and returns a
I have a simple windows service application I am trying to debug in VS
I have a simple windows Service developed in VS.net 2008 and VB.net. When I
enter code here Hi All, I have a simple windows service application that connects
I have a very simple windows Service that is developed in vb.net 2008. When

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.