multithreading - C# pass function with return and parameter to Thread -


i created function paramter , return value. following code:

static void main(string[] args)     {         string url = "url";          thread thread = new thread(             () => readfile(url)             );         thread.start();     }      public static bool readfile(string url)     {                        bool result = true;             return result;     } 

how can return value method inside of thread?

the signature method passed thread void method(object), in other words can't return anything. 1 way handle allow both thread , the main code access same variable, can used signal result:

class someclass {     private static bool threadresult;      static void main(string[] args)     {         string url = "url";          thread thread = new thread(() => readfile(url));         thread.start();         ...         // when thread completed, threadresult can read     }      private static void readfile(string url)     {                    threadresult = true;     } } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -