중첩 된 개인 클래스가있는 다음 클래스가 있는데 NID
값을 Context
에 할당하고 싶습니다. getter와 setter를 사용했지만 NID
(Sequencer.Context = value;
)의 값은 (SeqNode = Node.LoadNode(Context);
)에 할당되지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?개인 중첩 클래스의 개인 필드 값을 설정하는 방법은 무엇입니까?
//Instantiation
Increment.NID = "/Root/Dir/NodetoIncrement";
String getSequence = Convert.ToString(Increment.SID);
// The Class
public static class Increment
{
//Value of the node Context location in the tree to increment (Increment.NID)
public static string NID
{
set { Sequencer.Context = value; } //The "/Root/Dir/NodetoIncrement";
}
//Get the sequence ID
public static int SID
{
get { return Sequencer.GetSeqId; }
}
//Nested sequencer class. This increments the node.
private class Sequencer
{
private Node SeqNode;
private static int SequenceNumber;
private volatile bool Run = true;
public static string Context { get; set; } //gets
public static int GetSeqId
{
get
{
return Interlocked.Add(ref SequenceNumber, 1);
}
}
public Sequencer() //Constructor Here!
{
SeqNode = Node.LoadNode(Context);
SequenceNumber = Convert.ToInt16(SeqNode["LastSequenceNo"]);
//NEVER DO THIS .. causes the system to lockup see comments.
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
while (Run)
{
Save();
Thread.Sleep(5000);
}
});
}
private void Save()
{
//optimistic concurrency recommended!!
var retryMaxCount = 3; // maximum number of attempts
var cycles = 0; // current attempt
Exception exception = null; // inner exception storage
while (cycles++ < retryMaxCount) // cycle control
{
try
{
SeqNode["LastSequenceNo"] = Convert.ToString(SequenceNumber);
SeqNode.Save();
// successful save, exit loop
exception = null;
break;
}
catch (NodeIsOutOfDateException e)
{
exception = e; // storing the exception temporarily
SeqNode = Node.LoadNode(Context);
}
}
// rethrow if needed
if (exception != null)
throw new ApplicationException("Node is out of date after 3 attempts.", exception);
}
~Sequencer() { Save(); }
}
}
public class XYHandler : Node
{
public override void Save(NodeSaveSettings settings)
{
base.Name = Convert.ToString(Increment.SID);
base.Save();
}
public override bool IsContentType
{
get { return true; }
}
}
, 클래스는 이미 비공개입니다. 그냥 공개하고 문제를 해결하십시오. –
당신이 우리를 도와 줄 수있는 충분한 정보를 제공했다고 생각하지 않습니다. –
인스턴스를 추가했습니다. – Xdrone