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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:43:31+00:00 2026-06-15T22:43:31+00:00

Please consider the following simple code and then I will ask my question. public

  • 0

Please consider the following simple code and then I will ask my question.

public static void Save(XmlDocument saveBundle)
    {
        ThreadStart threadStart = delegate
        {
            SaveToDatabase(saveBundle);
        };

        new Thread(threadStart).Start();            
    }

The issue with using threads in Visual Studio (2005) is you can’t walk through them easily (I believe there is a way to switch threads which I have not looked into as I’m hoping there is an easier way).

So, in live, my code is more complex that then example above and we use a new thread as it’s time critical but the principal is the same. Most importantly, it is not time critical in test!

At the moment, I will probably do something like using the #if debug but it just feels wrong to do so – Am I using the #if in the correct way here or is there a better way to resolve this?

public static void Save(XmlDocument saveBundle)
    {

   #if debug
      {
        SaveToDatabase(parameters);
        }
   #else
        {
            ThreadStart threadStart = delegate
            {
                SaveToDatabase(parameters);
            };

            new Thread(threadStart).Start();
        }
   #endif
      }
    }

Although I’m stuck on .NET 2.0 I am interested in any version from .NET 20. onwards (I’m sure one day I’ll leave the Jurassic period and join everyone else)

  • 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-06-15T22:43:32+00:00Added an answer on June 15, 2026 at 10:43 pm

    If what you truly want to do is not use the threading in your debug build – this is the correct way to do it and probably the quickest and most capable way of doing it as well. It may look a bit ugly but the alternative are just more bools, configurations and other work arounds.

    If you’re interested in debugging the thread directly (this is important perhaps if concurrency is an issue! You should always test as close to the production environment as possible) then you can simply go (Debug -> Windows -> Threads) and then right click the thread you would like to debug and “Switch to Thread”.

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

Sidebar

Related Questions

Please consider the following simple use case: public class Foo { public virtual int
Please consider the following code: public class Person ( public string FirstName {get; set;}
Please consider the following java source: package com.stackoverflow; public class CondSpeed { private static
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
I know, this is very simple for you guys. Please consider the following code:
Please consider the following jQuery code: if ($(this).is(':hidden')) { $(this).show(); } My Question: Is
Please consider following code: 1. uint16 a = 0x0001; if(a < 0x0002) { //
Please consider the following code: mpz_t x, n, out; mpz_init_set_ui(x, 2UL); mpz_init_set_ui(n, 7UL); mpz_init(out);
Please consider the following code, struct foo { foo() { std::cout << Constructing! <<

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.