2013-05-31 50 views
0

静电功能,您好我改变我的计划,我增加了一个主题为它的功能之一,但我有一个错误工作线程

这是我第一次工作的主题。我发现了一个错误*.Checked == true

static bool Check_DIR_Attributes(DirectoryInfo DirInfo) 
    { 
     //check Attributes 
     FileAttributes Fattributes = new FileAttributes(); 
     Fattributes = DirInfo.Attributes; 

     SearchSetAttrib = new List<FileAttributes>(); 

     if (chkattributes.Checked == true) 
     { 
      SearchSetAttrib.Clear(); 
      if (chkreadonly.Checked == true) 
       SearchSetAttrib.Add(FileAttributes.ReadOnly); 
      if (chksystem.Checked == true) 
       SearchSetAttrib.Add(FileAttributes.System); 
      if (chkhidden.Checked == true) 
       SearchSetAttrib.Add(FileAttributes.Hidden); 
      if (chkNormal.Checked == true) 
       SearchSetAttrib.Add(FileAttributes.Normal); 
      if (chkArchiv.Checked == true) 
       SearchSetAttrib.Add(FileAttributes.Archive); 

      foreach (FileAttributes FileAtt in SearchSetAttrib) 
      { 
       if ((Fattributes & (FileAtt)) != 0) 
        ReAttrib = true; 
       else 
        return ReAttrib = false; 
      } 
     } 
     else 
      ReAttrib = true; 

     return ReAttrib; 
    } 
+0

你会得到什么错误? – Leri

+0

对象引用对于非静态字段是必需的,或者属性Search_File.Form1.chkAttributes – locerst

+0

@locerst查看下面的答案。 – aiapatag

回答

2

字段chkreadonlychksystem等不是静态的(他们不能轻易),所以从静态方法不起作用访问它们。

我的建议是

  • 要么使函数非静态
  • 或(如果由于某种原因不能)使用非静态的包装,以提供与以基准的静态方法实例
+1

你只是假设这些变量是由于它们的名称(复选框)的实例变量? :) – aiapatag

+0

好,如果我这样做非静态如何使用它的线程? – locerst

+1

@locerst你为什么认为该方法必须是静态的才能用于线程? – Dirk