结构属性不可用

时间:2017-02-13 15:34:35

标签: c# winforms struct windows-forms-designer

我有一个包含五个属性的结构,它们在按钮Sub CallbackGetVisible(control As IRibbonControl, ByRef visible) On Error GoTo err_Handle Const strError As String = "'CallbackGetVisible'" 'Don't Re-Set The Value If It's Already The Same If bShowActions = visible Then GoTo Cleanup visible = bShowActions GoTo Cleanup 'Set Any Objects to Nothing, Exits Routine Cleanup: Exit Sub 'Throw Error err_Handle: 'Handle your error here Resume Cleanup End Sub 方法(使用Windows窗体设计器)上设置。设置完毕后,使用_click运行bacground worker。然后在后台worker的.RunWorkerAsync方法中使用该结构。

但是,当我在_ _DoWork方法中调用struct时,struct all的属性值为null。谁能告诉我我做错了什么?我是C#的新手。

定义结构

DoWork

按钮点击功能(仅限相关代码)

struct 
FtpSetting
{
  public String Server { get; set; }
  public String Username { get; set; }
  public String Password { get; set; }
  public String FileName { get; set; }
  public String FullName { get; set; }
}
FtpSetting _inputParameter;

DoWork功能(仅限相关代码)

FileInfo fi = new FileInfo(ofd.FileName);
_inputParameter.Server = txtServer.Text;
_inputParameter.Username = txtServer.Text;
_inputParameter.Password = txtServer.Text;
_inputParameter.FileName = fi.Name;
_inputParameter.FullName = fi.FullName;
backgroundWorker.RunWorkerAsync();

1 个答案:

答案 0 :(得分:5)

这里null的内容不是struct的属性,而是Argument的所有属性。

你需要调用带有参数的RunWorkerAsync(object argument)的重载:

backgroundWorker.RunWorkerAsync(_inputParameter);