Mutlithreading:-Playing Mutiple Video files CPU 100%
-
Hi, I am doing an application that is using webservice & displaying data.So every 30 seconds the application will call webservice, I use system.Threading.Timer it is working fine.CPU usage is very less (maximum 30).I got an additional task to play video files.So it will be maximum 8 video in a screen (video files located in local system) & very 30 seconds according to data from ws video file will change.I write the code like this.In timer callback event I am Executing 2 functions [Code] System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetNextPage), state); // going 2 next page, in a page displaying 8 rows System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetNextVideo), state); // displaying corresponding video //in delegate of video I put the below code wmp = (AxWMPLib.AxWindowsMediaPlayer)Arrctrl[0]; //Find the control bcos adding at runtime thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(PlayCurrentWMP)); //PlayCurrentWMP is assign the URL & play thread.Priority = System.Threading.ThreadPriority.Lowest; thread.IsBackground = true; thread.Start(wmp); [/Code] Please advice what is wrong in my coding. Thanks in advance :confused:
-
Hi, I am doing an application that is using webservice & displaying data.So every 30 seconds the application will call webservice, I use system.Threading.Timer it is working fine.CPU usage is very less (maximum 30).I got an additional task to play video files.So it will be maximum 8 video in a screen (video files located in local system) & very 30 seconds according to data from ws video file will change.I write the code like this.In timer callback event I am Executing 2 functions [Code] System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetNextPage), state); // going 2 next page, in a page displaying 8 rows System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetNextVideo), state); // displaying corresponding video //in delegate of video I put the below code wmp = (AxWMPLib.AxWindowsMediaPlayer)Arrctrl[0]; //Find the control bcos adding at runtime thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(PlayCurrentWMP)); //PlayCurrentWMP is assign the URL & play thread.Priority = System.Threading.ThreadPriority.Lowest; thread.IsBackground = true; thread.Start(wmp); [/Code] Please advice what is wrong in my coding. Thanks in advance :confused:
Cant tell from what you told us. Some ideas/suggestions: - maybe movie takes more than 30 seconds - maybe you keep adding threads - add a thread counter; increment it at the beginning of the threaded method (PlayCurWMP) and decrement it at the end; show it all the time - maybe you are exhausting the ThreadPool - I would add logging in all relevant parts, so you get a history line of what is going on; - you even may try to correlate your CPU load (observed, or obtained programmatically) with that time line. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Cant tell from what you told us. Some ideas/suggestions: - maybe movie takes more than 30 seconds - maybe you keep adding threads - add a thread counter; increment it at the beginning of the threaded method (PlayCurWMP) and decrement it at the end; show it all the time - maybe you are exhausting the ThreadPool - I would add logging in all relevant parts, so you get a history line of what is going on; - you even may try to correlate your CPU load (observed, or obtained programmatically) with that time line. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
hi, Thanks for the reply.When I start the application I am adding control runtime.If I try to play the movie suddenly CPU usage become 100% & the application runs very slowly. Can you suggest is it AxWMPLib.AxWindowsMediaPlayer taking the memory? Every 30 seconds I am updating the screen using Threading.Timer & delegates.So id the screen changes I need to change all the videos. Can you pls help me How I play video with out affecting my screen display & reduce the CPU usage?I am not good in threading.Please give the code... Thanks a lot..
-
hi, Thanks for the reply.When I start the application I am adding control runtime.If I try to play the movie suddenly CPU usage become 100% & the application runs very slowly. Can you suggest is it AxWMPLib.AxWindowsMediaPlayer taking the memory? Every 30 seconds I am updating the screen using Threading.Timer & delegates.So id the screen changes I need to change all the videos. Can you pls help me How I play video with out affecting my screen display & reduce the CPU usage?I am not good in threading.Please give the code... Thanks a lot..
I dont have code for this. I gave you suggestions and ideas, that will be it. One more suggestion: make sure you dont have a thread touch a control it did not create (on old .NET, before 2.0) that may cause almost any anomaly; on .NET >= 2.0 it should give an InvalidOperationException with some cross-thread remark in the message. Thats all I can do for you. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }