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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:44:59+00:00 2026-05-27T22:44:59+00:00

I am implementing a class that will be used concurrently from multiple threads. Most

  • 0

I am implementing a class that will be used concurrently from multiple threads. Most of the properties get and set primitive types which can be handled properly by the Interlocked class. The class includes a Guid property. This is not as straight-forward to implement in a thread-safe manner. Is this how you would implement the property? Thanks in advance.

private Byte[] _activityId;
public Guid ActivityId 
    {
        get { return new Guid(this._activityId); }
        set
        {
            Byte[] bytes = value.ToByteArray();
            Interlocked.Exchange(ref this._activityId, bytes);
        }
    }

UPDATE: So the only proposed solution up to this point doesn’t include the use of any “Threading” classes or constructs. So I am going to pose the question that I’ve already posed in comments:

My understanding is that reference/primitive values types assignments are atomic however Interlocked will guarantee the change is propagated to all threads. If we could simply just assign the value, why does Interlocked expose APIs to exchange reference types and primitive values?

  • 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-27T22:45:00+00:00Added an answer on May 27, 2026 at 10:45 pm

    I think you could use the other overload of Interlocked.Exchange:

    private volatile object _activityId; // Yes, object :)
    public Guid ActivityId {
        get { return (Guid)_activityId; }
        set { _activityId = value; }
    }
    

    This works because the Guid is now boxed, and the assignment of reference types is atomic.

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

Sidebar

Related Questions

I'm implementing a class that wraps around an xml document with a very strictly
I can't find any documentation on implementing a class that inherits System.Windows.Media.Brush - what
Fixed: See notes at bottom I am implementing a generic class that supports two
I have a factory class that populates objects with data. I want to implementing
I'm implementing a cache in a class library that i'm using in an asp.net
I'm implementing a Python ontology class that uses a database backend to store and
I was recently tasked on implementing a buffer which will be used as a
I'm designing a library that will be used to intercept and process incoming messages
I have a simple class ExcelStringBuilder. Its used to build a string that can
Consider that I have a complex class structure where many elements inherit from other

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.