Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I searched Google and Code Project but I could not find anything useful.

My C# SoftPhone desktop app (using the .NET 3.5 Framework) needs to capture two data points from the voice interaction when the user initiates a transfer or conference call (I am already doing this) and store these two data points in an object that can be accessed later on by the app during the life of the voice interaction (phone call)

What I have tried:

I have tried creating a Singleton but I don't think I did it correct or it does not apply to my C# SoftPhone desktop app scenario
Posted
Updated 8-Nov-16 13:49pm
Comments
[no name] 8-Nov-16 14:10pm    
I would say a Singleton but since you didn't actually describe the actual problem with your code, it's kind of hard to say.
Gibran Castillo 8-Nov-16 14:30pm    
I don't know where to instantiate my singleton for the first time to then use it

I am thinking I instantiate the originalInboundData singleton class in the class where all init transfer and init conference are register with the app

My singleton C# class looks as follows:

public class OriginalInboundData
{
#region Field Declaration
private string dataPoint1 = "";
private string dataPoint2 = "";
private string dataPoint3 = "";
private string dataPoint4 = "";

private static OriginalInboundData instance = null;
private static readonly object padlock = new object();
#endregion

#region Properties Declaration
public string DataPoint1
{
    get { return dataPoint1; }
    set { dataPoint1 = value; }
}
 
public string DataPoint2
{
    get { return dataPoint2; }
    set { dataPoint2 = value; }
}
 
public string DataPoint3
{
    get { return dataPoint3; }
    set { dataPoint3 = value; }
}
 
public string DataPoint4
{
    get { return dataPoint4; }
    set { dataPoint4 = value; }
}
 
public static OriginalInboundData Instance
{
    get
    {
        lock (padlock)
        {
            if (instance == null)
            {
                instance = new OriginalInboundData();
            }
 
            return instance;
        }
    }
}
#endregion

#region Constructor
OriginalInboundData()
{
    //Do nothing
}


So I am not getting an error, I am trying to figured out where to call the singleton for the first time to them have access to it when I capture the data points during the init transfer or init conference
[no name] 8-Nov-16 14:48pm    
And the reason you can't instantiate your singleton at startup is because....?
[no name] 8-Nov-16 15:12pm    
Right right right. Sorry forgot we was talking about Singletons. The beauty of the singleton is that if you get the instance of the singleton and it doesn't already exist, it creates a new instance for you. Otherwise, you get the existing instance. So call it when you need it.

1 solution

You can create a static class that contains anything you want. I have one like that that I call "Globals".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900