home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
MediaPortal 1 Plugins
Popular Plugins
Fanart Handler
Latest Media Handler v2.4.X.000
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="arion_p" data-source="post: 1163352" data-attributes="member: 45945"><p>Even so, the above code is not thread safe. What if ActiveWindow changes between the call to GUIWindowManager.ActiveWindow and the call to GUIWindowManager.<strong>GetWindow</strong>()? What if when you call GUIWindowManager.<strong>GetWindow</strong>(), GUIWindowManager.Is in the middle of switching windows? (I haven't looked at the code and it's been quite a long time, but my guess is the GetWindow() does more than what is apparent to the eye - eg. actually load the window)</p><p></p><p></p><p>Not really. It is an error thrown early in the process of LoadSkin to avoid crashing later (which would be harder to recover). Also it warns the developer that he is doing something wrong, which might seem to work if this error was not thrown but may fail unexpectedly (it depends on timing).</p><p></p><p></p><p>You should avoid too many calls to Control.Invoke(), they are expensive. What Invoke does is it places the delegate in a queue and when the UI thread is idle it will poll that queue and execute the queued delegates. This causes high latency. In the meantime the calling thread is blocked (unless you use BeginInvoke in which case you can do other things in the calling thread and later check the result of the call). You should not use Invoke to call simple methods repeatedly (eg call AddItem() 100 times). i.e.</p><p>Don't do this:</p><p>[Code]</p><p>for(i=1; i<100; i++)</p><p>{</p><p> control.Invoke(delegate { list.AddItem(i.ToString()); });</p><p>}</p><p>[/Code]</p><p>Do this instead:</p><p>[Code]</p><p>control.Invoke(delegate {</p><p> for(i=1; i<100; i++)</p><p> {</p><p> list.AddItem(i.ToString());</p><p> }</p><p>});</p><p>[/Code]</p><p></p><p>Edit: I am not sure this delegate {} syntax is correct. You may have to use either new MethodInvoker() or new Action()</p></blockquote><p></p>
[QUOTE="arion_p, post: 1163352, member: 45945"] Even so, the above code is not thread safe. What if ActiveWindow changes between the call to GUIWindowManager.ActiveWindow and the call to GUIWindowManager.[B]GetWindow[/B]()? What if when you call GUIWindowManager.[B]GetWindow[/B](), GUIWindowManager.Is in the middle of switching windows? (I haven't looked at the code and it's been quite a long time, but my guess is the GetWindow() does more than what is apparent to the eye - eg. actually load the window) Not really. It is an error thrown early in the process of LoadSkin to avoid crashing later (which would be harder to recover). Also it warns the developer that he is doing something wrong, which might seem to work if this error was not thrown but may fail unexpectedly (it depends on timing). You should avoid too many calls to Control.Invoke(), they are expensive. What Invoke does is it places the delegate in a queue and when the UI thread is idle it will poll that queue and execute the queued delegates. This causes high latency. In the meantime the calling thread is blocked (unless you use BeginInvoke in which case you can do other things in the calling thread and later check the result of the call). You should not use Invoke to call simple methods repeatedly (eg call AddItem() 100 times). i.e. Don't do this: [Code] for(i=1; i<100; i++) { control.Invoke(delegate { list.AddItem(i.ToString()); }); } [/Code] Do this instead: [Code] control.Invoke(delegate { for(i=1; i<100; i++) { list.AddItem(i.ToString()); } }); [/Code] Edit: I am not sure this delegate {} syntax is correct. You may have to use either new MethodInvoker() or new Action() [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
MediaPortal 1 Plugins
Popular Plugins
Fanart Handler
Latest Media Handler v2.4.X.000
Contact us
RSS
Top
Bottom