c# - Cannot convert from method group to System.Func<string> -
i'm playing bit .net 4.0 task class download google webpage in background using thread. problem if function has 1 or more parameters, application won't compile (idk how pass parameter). wonder how can pass function's parameter in dowork() method.
this works:
public task<string> dowork() { //create task, of runs our work of thread pool thread return task.factory.startnew<string>(this.downloadstring); } private string downloadstring() { using (var wc = new webclient()) return wc.downloadstring("http://www.google.com"); } this doesn't:
public task<string> dowork() { //create task, of runs our work of thread pool thread return task.factory.startnew<string>(this.downloadstring); } private string downloadstring(string uri) { using (var wc = new webclient()) return wc.downloadstring(uri); } the error is:
cannot convert 'method group' 'system.func<string>' thank in advance!
return task.factory.startnew(() => this.downloadstring("http://...."));
Comments
Post a Comment