2013-05-31 111 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