工作线程的静态函数

时间:2013-05-31 06:47:25

标签: c# static

嗨我改变了我的一个程序,我为其功能添加了一个Thread,但我有一个错误

这是我第一次使用Threads。我在*.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;
    }

1 个答案:

答案 0 :(得分:2)

字段chkreadonlychksystem等不是静态的(并且它们不容易),因此从静态方法访问它们将无效。< / p>

我的建议是

  • 使功能非静态
  • 或(如果由于某种原因不可能)使用非静态包装器为静态方法提供对实例的引用