c# - New Thread does not see the supplied method from the same namespace -


i new c# , trying figure out doing wrong in following script. getting error "method name expected" when starting new thread "del" delegate. method geturlthread defined , delegate del pointing why not being seen? thank you.

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.net; using system.io; using system.threading;  namespace updatenewfrontend {     public partial class frmmain : form     {          public frmmain()         {             initializecomponent();         }          // define function pointer         // =======================         public delegate string geturlthreaddelegate(string targeturl);          // define function function pointer         // ========================================         public string geturlthread(string targeturl)         {              httprequestclass urlresponsetext = new httprequestclass();              urlresponsetext.targeturl = targeturl;              string text = urlresponsetext.geturlresponse();              return text;         }           private void btnurl_click(object sender, eventargs e)         {             // top decalrations             // ================              .... code here....              string targeturl = "some string here...";               // instantiate http call object "targeturl" url             // =======================================================              geturlthreaddelegate del = new geturlthreaddelegate(geturlthread);               thread t1 = new thread(new threadstart(del(targeturl))); // error here !!!             t1.start();               .... more code here....          }      } } 

it's not clear you're trying achieve, you're calling del here:

new thread(new threadstart(del(targeturl))) 

you've got fundamental problem though - method you're trying call doesn't have right signature threadstart (which void parameterless delegate). it's not clear want response returned geturlthread, use lambda expression call method more without declaring own delegate type:

thread t1 = new thread(() => geturlthread(targeturl)); t1.start(); 

that fetch value - throw away.

as aside - important 1 - really readability of code if you'd follow .net naming conventions. namespace, type , method names should pascalcased, not camelcased.

additionally, might want consider using async/await... or @ least use task<t> if you're using .net 4.0 or higher.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -

jquery - Keeping Kendo Datepicker in min/max range -