Comments on: Getting back to the UI Thread in Silverlight 2 Beta 2 http://gen5.info/q/2008/06/25/getting-back-to-the-ui-thread-in-silverlight-2/ Towards Intelligent Systems Wed, 11 Jul 2012 12:59:08 +0000 hourly 1 http://wordpress.org/?v=3.0.3 By: admin http://gen5.info/q/2008/06/25/getting-back-to-the-ui-thread-in-silverlight-2/comment-page-1/#comment-558 admin Tue, 08 Jul 2008 15:04:10 +0000 http://gen5.info/q/?p=33#comment-558 @Joel, I'm having trouble confirming your solution. Maybe I'm doing something wrong, but if I try your example, Visual Studio says "Cannot access non-static method 'BeginInvoke' in static context;" I also fail to see any static members for System.Windows.Threading.Dispatcher in the Silverlight API reference. Am I missing something? @Joel, I’m having trouble confirming your solution.

Maybe I’m doing something wrong, but if I try your example, Visual Studio says “Cannot access non-static method ‘BeginInvoke’ in static context;” I also fail to see any static members for System.Windows.Threading.Dispatcher in the Silverlight API reference.

Am I missing something?

]]>
By: Joel Neubeck http://gen5.info/q/2008/06/25/getting-back-to-the-ui-thread-in-silverlight-2/comment-page-1/#comment-557 Joel Neubeck Thu, 03 Jul 2008 20:10:22 +0000 http://gen5.info/q/?p=33#comment-557 Great blog post on what is happening in SLBeta 2. One thing to note...you can just use Dispatcher.BeginInvoke(MyMethod). There is no need to take it from "Application.Current.RootVisual.Dispatcher" or store a second reference statically. -Joel http://joel.neubeck.net/ Great blog post on what is happening in SLBeta 2.

One thing to note…you can just use Dispatcher.BeginInvoke(MyMethod). There is no need to take it from “Application.Current.RootVisual.Dispatcher” or store a second reference statically.

-Joel
http://joel.neubeck.net/

]]>
By: Generation 5 » How Asynchronous Execution Works in RIAs http://gen5.info/q/2008/06/25/getting-back-to-the-ui-thread-in-silverlight-2/comment-page-1/#comment-555 Generation 5 » How Asynchronous Execution Works in RIAs Fri, 27 Jun 2008 01:41:49 +0000 http://gen5.info/q/?p=33#comment-555 [...] components must be done from the user interface thread.  (Fortunately,  it’s easy to get back to the UI thread.)  Subscribe to our RSS Feed to keep informed of breaking developments in Silverlight [...] [...] components must be done from the user interface thread.  (Fortunately,  it’s easy to get back to the UI thread.)  Subscribe to our RSS Feed to keep informed of breaking developments in Silverlight [...]

]]>
By: admin http://gen5.info/q/2008/06/25/getting-back-to-the-ui-thread-in-silverlight-2/comment-page-1/#comment-554 admin Thu, 26 Jun 2008 19:50:52 +0000 http://gen5.info/q/?p=33#comment-554 Jack, Application.Current.RootVisual.Dispatcher doesn't work. I get "Unauthorized Cross Thread Exception." There are a number of good reasons why asynchronous communications should be decoupled from the user interface thread. Here are two of them: (1) As asynchrononous RIAs increase in complexity, they eventually need a notification infrastructure for data changes. The issue that there might be N user interface elements that are affected when a piece of data changes. Trying to hardwire all of these updates will drive you nuts. (I've tried it.) It's better for UI elements to register their interest in certain data items and then let the notifier take over. The notifier will probably flip to the UI thread and then enumerate over all the subscribers: not flip over for each individual subscriber, or expect each subscriber to flip the thread itself. (2) Code reuse. In a lot of cases we end up developing multiple apps and product lines, even when it's just a few different test apps that are used in house. Often we write chunks of functionality that get used in multiple apps: it's usually better to put "the tough stuff" like concurrency control into the reusable parts (which don't know how they'll be reused) rather than re-write them in the code that does the reusing. Jack, Application.Current.RootVisual.Dispatcher doesn’t work. I get “Unauthorized Cross Thread Exception.”

There are a number of good reasons why asynchronous communications should be decoupled from the user interface thread. Here are two of them:

(1) As asynchrononous RIAs increase in complexity, they eventually need a notification infrastructure for data changes. The issue that there might be N user interface elements that are affected when a piece of data changes. Trying to hardwire all of these updates will drive you nuts. (I’ve tried it.) It’s better for UI elements to register their interest in certain data items and then let the notifier take over. The notifier will probably flip to the UI thread and then enumerate over all the subscribers: not flip over for each individual subscriber, or expect each subscriber to flip the thread itself.

(2) Code reuse. In a lot of cases we end up developing multiple apps and product lines, even when it’s just a few different test apps that are used in house. Often we write chunks of functionality that get used in multiple apps: it’s usually better to put “the tough stuff” like concurrency control into the reusable parts (which don’t know how they’ll be reused) rather than re-write them in the code that does the reusing.

]]>
By: Jack Bond http://gen5.info/q/2008/06/25/getting-back-to-the-ui-thread-in-silverlight-2/comment-page-1/#comment-552 Jack Bond Thu, 26 Jun 2008 18:40:28 +0000 http://gen5.info/q/?p=33#comment-552 You've already got one: Application.Current.RootVisual.Dispatcher I'm not sure what you mean by "get at a ScriptObject or UIElement statically don’t seem to work off when you’re not in the UI Thread." If you are attempting to update a UIElement, presumably you've got a reference to it, at which point you can call CheckAccess and BeginInvoke if required. If you are attempting to BeginInvoke some arbitrary code on the UI thread, then you've got the static reference I listed above. You’ve already got one:

Application.Current.RootVisual.Dispatcher

I’m not sure what you mean by “get at a ScriptObject or UIElement statically don’t seem to work off when you’re not in the UI Thread.”

If you are attempting to update a UIElement, presumably you’ve got a reference to it, at which point you can call CheckAccess and BeginInvoke if required. If you are attempting to BeginInvoke some arbitrary code on the UI thread, then you’ve got the static reference I listed above.

]]>
By: admin http://gen5.info/q/2008/06/25/getting-back-to-the-ui-thread-in-silverlight-2/comment-page-1/#comment-551 admin Thu, 26 Jun 2008 14:58:20 +0000 http://gen5.info/q/?p=33#comment-551 Jack, I checked this and you're right. However, you might not have a reference to a UIElement handy at the place where you want to switch to the UI Thread -- I still think it's good to have a Dispatcher squirreled away in a static field somewhere, because most of the obvious ways to get at a ScriptObject or UIElement statically don't seem to work off when you're not in the UI Thread. Personally, I like having 'choke points' in my apps that let me control concurrency on an app-wide basis. It took me less than half an hour for me to adjust to the changes between beta 2 and beta 1 because I only needed to change one method... It's much better to have a standard method you call rather than to grasp for whatever random UIElement you can find in a situation. Jack, I checked this and you’re right.

However, you might not have a reference to a UIElement handy at the place where you want to switch to the UI Thread — I still think it’s good to have a Dispatcher squirreled away in a static field somewhere, because most of the obvious ways to get at a ScriptObject or UIElement statically don’t seem to work off when you’re not in the UI Thread.

Personally, I like having ‘choke points’ in my apps that let me control concurrency on an app-wide basis. It took me less than half an hour for me to adjust to the changes between beta 2 and beta 1 because I only needed to change one method… It’s much better to have a standard method you call rather than to grasp for whatever random UIElement you can find in a situation.

]]>
By: Jack Bond http://gen5.info/q/2008/06/25/getting-back-to-the-ui-thread-in-silverlight-2/comment-page-1/#comment-546 Jack Bond Thu, 26 Jun 2008 02:57:15 +0000 http://gen5.info/q/?p=33#comment-546 There's no chicken and egg, it's perfectly safe to access a UIElement's Dispatcher object from any thread. There would be little point in having it be a public property otherwise. You can also call a UIElement's CheckAccess method from any thread without encountering any UnauthorizedAccessExceptions. There’s no chicken and egg, it’s perfectly safe to access a UIElement’s Dispatcher object from any thread. There would be little point in having it be a public property otherwise. You can also call a UIElement’s CheckAccess method from any thread without encountering any UnauthorizedAccessExceptions.

]]>

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /hosting/sites/gen5.info/htdocs/q/wp-includes/class-snoopy.php on line 1148

Warning: fsockopen(): unable to connect to :80 (php_network_getaddresses: getaddrinfo failed: No address associated with hostname) in /hosting/sites/gen5.info/htdocs/q/wp-includes/class-snoopy.php on line 1148