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

  • Home
  • SEARCH
  • 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 6579917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:57:30+00:00 2026-05-25T15:57:30+00:00

I really am feeling bad. I have one web application that sends Emails for

  • 0

I really am feeling bad.

I have one web application that sends Emails for notifications.

It is a class that contains a basic method that sends a email like this:

 MailMessage email = new MailMessage();

        email.To.Add("xxx@gmail.com");

        email.Subject = "Test";
        email.Body = "t";

        SmtpClient client = new SmtpClient();

        client.Send(email);

But i have a service called NotificatorService that verify some logic, and because this is just a “extra” the method for this service is called in a new Thread.. What i do is this:

public void NotifyMembers(NotificatorClientDTO clientDto) {
if(clientDto == null)
    throw new ArgumentNullException("clientDto");


Thread t = new Thread( 
    () => {
    // go to database, verify business rules, etc...

    // At the end if it is ok, invoke the method that sends a email
}

t.Start()

}

If i create a unit test that instantiates the NotificatorService and call notifyMembers with some data, the code will throw an exception but only if i execute in a seperated thread.

The thread that i create is setted at foregronnd so the system don’t destroy my process i suppose.

THe exception message is this:

SmtpException: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I walk to 2 inner exceptions and i see this

_message “Thread was being aborted.” string

Why this is happening?
What causes the thread to be aborted?

  • 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-25T15:57:31+00:00Added an answer on May 25, 2026 at 3:57 pm

    Change your unit test to take an IMailService or something similar as a dependency. Then your web application unit test doesn’t need to do anything real in terms of sending emails – it can use a fake or a mock.

    You then need to create a production implementation of IMailService of course – and unit testing that may still be challenging, but at least you’ll then be only interested in testing mail handling, which means you may be able to change the constraints somewhat.

    You can potentially do the same for the thread creation side of things. Basically, try to separate out the “nasty bits” of your code (which interact with mail services and threads) from the real logic you want to test.

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

Sidebar

Related Questions

I have a feeling that this should really not be all that difficult, yet
I have the feeling that I'm missing the obvious, but have not succeeded with
This is my first post and I have the feeling that this is something
I do have somewhat of a feeling that people will try to beat me
Really my question has more to do with the server-side scrubbing of html that's
I really feel that I should learn Lisp and there are plenty of good
I really enjoyed Jeff's post on Spartan Programming . I agree that code like
I really want to write .NET apps that run on any platform (PC, Linux
I really like the fact that Microsoft has taken a commitment to bring MVC
Let's say you have a bug that was found in functional testing of a

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.