Errore: Object reference not set to an instance of an object.
Perché SynchronizationContext.Current è null?
L'algoritmo seguente funziona. ho provato, poi ho tolto il progetto Winform
in un'altra directory e SynchronizationContext.Current
è null
. Perché?
SynchronizationContext uiCtx = SynchronizationContext.Current;
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
int[] makeSelfMoves = new int[4];
lock (replay)
{
// count should be more than 2
foreach (KeyValuePair<int, int[]> item in replay)
{
makeSelfMoves = replay[item.Key];
codeFile.ExecuteAll(makeSelfMoves[0],
makeSelfMoves[1], makeSelfMoves[2], makeSelfMoves[3]);
// i get the error here. uictx is null
uiCtx.Post(o =>
{
PrintPieces(codeFile.PieceState());
}, null);
System.Threading.Thread.Sleep(1000);
}
}
}
quale contesto * è * si esegue questo codice in poi? Un'app per console? –
winform application –
E cosa sta creando un'istanza di questo oggetto e quando? (Sembra che tu stia catturando il contesto di sincronizzazione * * sulla costruzione dopo tutto.) –