我正在调用一个并行的方法,它工作正常,但我想让它传递一个对象.
这有效:
static void main()
{
Parallel.ForEach(_queued, new ParallelOptions { MaxDegreeOfParallelism = config.downloadthreads }, DownloadFile);
}
public static void DownloadFile(string url)
{....
}
Run Code Online (Sandbox Code Playgroud)
但我想要做的是通过配置这是我刚才所定义的类downloadfile方法.我一直在我的设置和其他东西保持在类中,然后更新它们,以便我不需要在整个地方传递变量.但是当我尝试这个时,我得到了一堆错误
无法从void转换为system.action,_queued是一个concurrentqueue
Parallel.ForEach(_queued, new ParallelOptions
{ MaxDegreeOfParallelism = config.downloadthreads }, DownloadFile(_queued, config));
public static void DownloadFile(string url, blogconfig tumblogconfig)
Run Code Online (Sandbox Code Playgroud) 我有一个ObservableCollection,我甚至先检查它以确保它有元素.然而,我仍然得到一个nullReferenceException(有时候,这从未出现过winrt 8.1版本的问题,我将其更改为UWP.)代码如下,它给出了错误,其中a.Url是:
if (sTumblrblog_gv_list.Count != 0)
{
if (tumblogconfig.ShowNSFWBlogs)
sTumblrGridView.ItemsSource = sTumblrblog_gv_list.OrderBy(a => a.Url);
else
sTumblrGridView.ItemsSource = sTumblrblog_gv_list.OrderBy(a => a.Url).Where(a => a.IsNsfw == false);
}
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Tumblr-FIA
StackTrace:
at tumblr_fia.MainPage.<>c.<updatestats>b__47_1(sTumblrblog_gv a)
at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
at System.Runtime.InteropServices.WindowsRuntime.EnumeratorToIteratorAdapter`1.MoveN
ext()
at System.Runtime.InteropServices.WindowsRuntime.EnumeratorToIteratorAdapter`1.get_HasCurrent()
InnerException:
Run Code Online (Sandbox Code Playgroud)
我理解这个错误我相信,但我检查sTumblrblog_gv_list不是空值.而我现在有一个尝试和捕获.有时我还会收到错误.