why we need lock to read or write variables, if we don't use lock, sometimes a deadlock will occur.
writing variable:
private void WriteValue(string name,object value) { Variables variables = Dts.Variables; try { Dts.VariableDispenser.LockOneForWrite(name, ref variables); variables[name].Value = value; } finally { if (variables.Locked) { variables.Unlock(); } } }
reading variable:
private object ReadValue(string name) { Variables variables = Dts.Variables; try { Dts.VariableDispenser.LockOneForRead(name, ref variables); return variables[name].Value; } finally { if (variables.Locked) { variables.Unlock(); } } }
more information: