Accessing UI element from within Async method in C#

Hi I was struggling a lot with Async method and accessing the elements of GUI (Like textbox) once async method is under-way. Was struggling with everything I found on net and also esoteric looking LAMBDA expressions without success. I posted about it in this thread

Now I have come up with ingenious method to do so all by myself and is feeling very proud of it. What I did was pass the UI element textbox.text to a class and save it there in a static variable using constructor. Now access/read the static variable from within async method. Simple. In same way I was able to to put result of async method back to GUI.

I know its too simple and something too obvious, but I was struggling. It just so happened that I opened a book and chanced upon a chapter explaining constructor and static variable !!! VoilĂ  got the idea then and there.

My code is all about shortening the long URL to small using API. Complete code here

by manmeetvirdi via /r/csharp

Leave a Reply