C# 为什么我会得到一个“;“请求对象引用”;这件事怎么样?

C# 为什么我会得到一个“;“请求对象引用”;这件事怎么样?,c#,multithreading,events,C#,Multithreading,Events,我正在尝试使用从第二个线程引发的自定义事件。以下是守则的相关部分: delegate void SearchCompleteHandler(Dictionary<string, List<string>> results); event SearchCompleteHandler SearchComplete; public static void Search() { Dictionary<string, List<string>> r

我正在尝试使用从第二个线程引发的自定义事件。以下是守则的相关部分:

delegate void SearchCompleteHandler(Dictionary<string, List<string>> results);
event SearchCompleteHandler SearchComplete;

public static void Search()
{
    Dictionary<string, List<string>> result = new Dictionary<string, List<string>>();
    SearchComplete?.Invoke(result);
}

SearchComplete = new SearchCompleteHandler(ShowSearchResults);
SearchComplete += new SearchCompleteHandler(ShowSearchResults);
dupeSearchThread = new System.Threading.Thread(Search);
dupeSearchThread.Start();
VS说“这个非静态属性需要一个对象引用”(近似thanslation)


我认为在使用事件之前添加一个处理程序就足够了。我该怎么办?

发生这种情况是因为您引用的对象根本不是静态的:您应该从搜索方法中删除关键字static,以便在类的实例中访问它,从而使它能够访问其中实例化的所有变量和对象。

发生这种情况是因为您引用一个完全不是静态的对象:您应该从搜索方法中删除关键字static,以便在类的实例中可以访问它,从而使它能够访问其中实例化的所有变量和对象

SearchComplete?.Invoke(result);