0

I need help in determining if I should use a shared function or not. I should use a shared function if the value returned applies to the entire application, because a shared variable is stored in memory only once. If that is true, then I suppose my answer is no, I should not be using a shared function.

Right now I have shared function that returns a string based on what parameters are passed. If the page that uses this code is viewed by multiple people at once, will the function produce undesirable results?

Public Shared Function ToFeaturelHTML(ByVal has As Boolean, ByVal feature As String)

If has = True Then
  Return String.Format("<li class='feature yes'>{0}</li> ", feature)
Else
  Return String.Format("<li class='feature no'>{0}</li> ", feature)
End If

End Function

1 Answer 1

1

The function you provide does not access any shared state (i.e. it's not using any shared variables). Every call will use its own copy of both parameters ("has" and "feature"). Plus, inside your function you are calling a shared function of String, which is a thread safe type.

In these conditions, your function will not produce any undesirable results when accessed from multiple clients.

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

I had the assumption that the parameters would use shared state. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.