winforms - C# in Windows Form Application, how can I get the label to auto-refresh from UDP client? -


right now, have button creates event decimal read udp listener (in different class), , being converted tostring() label. if run udp listener in console window, updates in real time fine. here, updates label in first instance, , stops refreshing. i've tried calling udplistener asynchronously still unable auto-refresh label.

private void btnbopit_click(object sender, eventargs e)         {         string firstticker, secondticker;         int mycurrentport;                      string portnumber = textportnumber.text;         mycurrentport = convert.toint32(portnumber);          firstticker = textfirstticker.text;         secondticker = textsecondticker.text;  //i call udpmethod asynchronously right here, , have async outside btn loop           calludpmethod(mycurrentport, firstticker, secondticker);         this.labelspread.refresh();     }       private async void calludpmethod(int port, string symb1, string symb2)     {         var result =await myudpmethodasync(port, symb1, symb2);         this.labelspread.text = convert.tostring(result);  //right here^^^^^^ want labelspread.text auto update, //gives me first instance , not refresh      }      private task<decimal> myudpmethodasync(int port, string symb1, string symb2)     {         return task.factory.startnew(() => myudpmethod(port, symb1, symb2));     }      private decimal myudpmethod(int port, string symb1, string symb2)     {         udplistener mylistener = new udplistener();         decimal result = mylistener.spreadvalue(port, symb1, symb2);         return result;     } 

i've tried using following code instead of async method in btn loop. but, gives me first instance of decimal spread:

    udplistener mylistener = new udplistener();     decimal spread = mylistener.spreadvalue(mycurrentport, firstticker, secondticker);     labelspread.text = convert.tostring(spread); 


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo