0

Here is the code I am using:

private static WeightRecordsDataSource sharedDataSource;

public static WeightRecordsDataSource SharedDataSource
        {
            get
            {
                if (sharedDataSource == null)
                    sharedDataSource = new WeightRecordsDataSource();

                return sharedDataSource;

            }

        }

However, every time SharedDataSource is called, the sharedDataSource is found to be null! and hence a new WeightRecordsDataSource is called. What am I doing wrong?

Abdalrahman Shatou
  • 4,550
  • 6
  • 50
  • 79
  • Make it thread safe, see this answer: http://stackoverflow.com/questions/100081/whats-a-good-threadsafe-singleton-generic-template-pattern-in-c-sharp – juju Sep 05 '13 at 19:50
  • How are you calling this? What are you calling it from? The singleton exists within a Process. For example in SSIS, if I have a singleton in a C# script, it appears the next time its called within the same SSIS Run the singleton no longer exists. Suggesting that the C# Script in a Task, within the same Run is run out of process with Variables passed into it. – CodeCowboyOrg Aug 19 '14 at 21:26

0 Answers0