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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:14:14+00:00 2026-05-27T03:14:14+00:00

I have a web service and some methods and I do NOT want to

  • 0

I have a web service and some methods and I do NOT want to use this code below, which works fine, because I intend to use this in a multi-threaded app where static (I have read) is not thread safe.

So, what I have done now is simply repeat the code that is in the static method ‘returnisTrue()’ below, in the body of my web service method “myWebMethod”, at points //1 of 3, //2 of 3, and //3 of 3. This works fine but results in bloated code. Is there a more compact way, using functional programming or anonymous methods or what have you that I can use?

Note the compiler choked when I tried to create a class inside the method…which would have solved my problem.

As I say the code I have now works fine but it is bloated, as I repeat the ‘static’ method ‘returnisTrue’ three times.

Thank you.

EDIT: in response to some questions about making my static method thread safe, which I rather not bother with, but in the interest of getting a solution I include below.

All this code is server side in a web service

// I cannot unfortunately use this static method below--not thread safe
static private bool returnisTrue()
{
  bool isTrue = false;
  // do a bunch of stuff here
  return isTrue;
}

public  bool myWebMethod (string XYZ)
{
  //public Class myClassReturnisTrue  { … }  //will not compile

  bool isTrueOrNot1 = returnisTrue(); //1 of 3

  /// more code here

  bool  isTrueOrNot2 = returnisTrue(); //2 of 3

  ///more code here

  bool isTrueOrNot3 = returnisTrue(); //3 of 3

  return isTrueOrNot1 && isTrueOrNot2 && isTrueOrNot3;
}
 // here is the static method 'returnisTrue' it looks something like this:


 static private bool returnIsTrue(string A, string B)
 {
 if (A.Length() < B.Length())
     {
return true;
     }
else
return false;

 }
  • 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-27T03:14:15+00:00Added an answer on May 27, 2026 at 3:14 am

    What are you actually doing within your static method? Are you modifying any global state or are you only working on local variables? There is nothing wrong with using static methods, or even variables, as long as you take proper measures to make sure that your code within is actually thread-safe.

    Both static methods and instance methods can potentially be unsafe depending on what you are doing within them. The main question to ask is, are you accessing any data that is accessible between multiple threads within your method? And if so, why not change your method to be thread-safe (through for example locking).

    Take a look for example at the .NET framework itself, it contains various static thread-safe methods throughout.

    Edit:

    Ok, now that we’ve seen your method – it is indeed thread-safe already. The method is not accessing any shared data and strings are immutable and inherently thread-safe as a result.

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

Sidebar

Related Questions

I have some types which are generated by a web service reference. I want
i want use some data from a website with web service. i have a
Some existing web services I consume have methods that look something like this: List<Employee>
I have a web service , i add some extra class which have message
I have an ASP.NET web service which does some heavy lifting, like say,some file
I have created a web service which is saving some data into to db.
We have a web service running on the server. We want to use the
I have a web service method where I would like to throw some custom
I have a WPF application in VS 2008 with some web service references. For
This is probably a simple one... Right now I have a working web service

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.