Answer the question
In order to leave comments, you need to log in
Accessing control from another thread?
There is a program on winforms. Double-clicking on the listview starts playing an internet radio station. But since the form freezes for a couple of seconds with each click, I decided to execute the Play method in another thread. The program works correctly, but if you run the program under a debugger, an "InvalidOperationException" exception appears.
The Play method takes 2 parameters - a string with the stream url and a float volume. I take the Url from the database through the GetUrlFromDB method (I pass the name of the radio station from the listview as a parameter and get the url by name). I decided to modify the code a little and when I click on the listview, I first pass the url to the tmp variable of the string type, and I already pass the url from the tmp variable to the Play method. The studio stopped swearing and everything works as it should. Is it possible to do so? I just looked at the examples (MSDN, stackoverflow), so there you need to write a lot of code, you need to create several additional methods and delegates, which is a bit complicated for me at the moment.
Working code:
Answer the question
In order to leave comments, you need to log in
Use the invoke method on lv.
lv.Invoke((MethodInvoker)delegate { lv.FocusedItem...; };
https://docs.microsoft.com/en-us/dotnet/api/system...
I decided to modify the code a little and when I click on the listview, I first pass the url to the tmp variable of the string type, and I already pass the url from the tmp variable to the Play method. The studio stopped swearing and everything works as it should. Is it possible to do so?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question