Answer the question
In order to leave comments, you need to log in
Access from another thread, Invoke hanging, how to solve?
There is a function that is written to Action.
void videoRecieved(Google.Apis.YouTube.v3.Data.Video video)
{
Debug.WriteLine(video.Id);
this.Invoke((Action)(
() => progressBar.Value = progressBar.Maximum
));
Debug.WriteLine(video.Id);
}
Answer the question
In order to leave comments, you need to log in
Invoke() raises the event not on a new thread, but on the main GUI thread of the application, and waits for the event to be processed. Probably, the GUI thread is busy with something and cannot process the event. Well, or the GUI thread, when progressBar.Value changes, should do something with video, but it cannot do this, because the video thread is blocked by waiting for the GUI thread.
option 1: figure out what the GUI thread is doing or blocking;
option 2: use BeginInvoke() - trigger the event but don't wait. Then the calling thread is not blocked, but there is no guarantee that upon exiting BeginInvoke() progressBar.Value has already changed its value, and will change it someday.
Yes, instead of this.Invoke((Action)(..) it is better to write progressBar.Invoke((Action)(..), but you need to change the progressBar - that means you need to do it in its thread.
The question is in which thread this function is called.
Instead this.Invoke
put Dispatcher.BeginInvoke
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question