码迷,mamicode.com
首页 > 其他好文 > 详细

Script Component 引用package variable

时间:2015-05-26 23:03:29      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

ScriptComponet 的变量分为两种类型,ReadOnly和ReadWrite,使用C#引用这两种类型的变量,有一点不同。

1,创建两个变量

技术分享

2,将变量传递给script component

技术分享

3,在script component中引用变量有两种方式

3.1 使用变量名作为来引用变量

        int code = this.Variables.VarCode;
        //string name = this.Variables.VarName;
        //this.Variables.VarName = "New VarName";

在引用ReadWrite类型的变量时,可能会发生异常“在PostExecute之外不能锁定变量集合进行读写访问”,就是说,不能在PostExecute函数之外通过这种方式引用ReadWrite类型的变量,如果发生这种异常,只需要将引用ReadWrite类型的变量的代码放到PostExecute中就不会出错了。

技术分享

3.2使用加锁方式来引用变量,这种方式能在PostExecute函数之外引用ReadWrite类型的变量

        this.VariableDispenser.LockForRead("User::VarCode");
        this.VariableDispenser.LockForWrite("User::VarName");

        IDTSVariables100 vars = null;
        this.VariableDispenser.GetVariables(out vars);

        int iCode = int.Parse(vars["User::VarCode"].Value.ToString());
        string strName = vars["User::VarName"].Value.ToString();
        vars["User::VarName"].Value = "New VarName";

        vars.Unlock();

 

Script Component 引用package variable

标签:

原文地址:http://www.cnblogs.com/ljhdo/p/4531844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!