<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.silverlight.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Silverlight Controls and Silverlight Toolkit</title><link>http://forums.silverlight.net/forums/35.aspx</link><description>Discussions around using and developing Silverlight controls and the Silverlight Toolkit</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Re: Prompts, Alerts, Dialogs, etc</title><link>http://forums.silverlight.net/forums/thread/242646.aspx</link><pubDate>Sun, 05 Jul 2009 01:07:25 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:242646</guid><dc:creator>maxima120</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/242646.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=35&amp;PostID=242646</wfw:commentRss><description>&lt;p&gt;Cool thank you&lt;/p&gt;</description></item><item><title>Re: Prompts, Alerts, Dialogs, etc</title><link>http://forums.silverlight.net/forums/thread/242568.aspx</link><pubDate>Sat, 04 Jul 2009 16:30:49 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:242568</guid><dc:creator>ksleung</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/242568.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=35&amp;PostID=242568</wfw:commentRss><description>&lt;p&gt;No I didn&amp;#39;t write it (too busy with other things).&amp;nbsp; I may write up something nice in a few days...&amp;nbsp; I have a SyncWebClient which does synchronous web client with all the bells and whistles including async cancellation, timeout, etc, for my own project.&lt;/p&gt;&lt;p&gt;But let me just tell you the basic idea so you can do it yourself.&amp;nbsp; It is rather simple.&lt;/p&gt;&lt;p&gt;(1) First, make sure you understand that if your function is running in the UI thread, it absolutely cannot block because (a) this is very bad for UI responsiveness, and (b) WebClient and GUI update and many other operations work only on the UI thread, and if you are blocking the UI thread they won&amp;#39;t get the chance to finish and hence they won&amp;#39;t get the chance to unblock, hence deadlock.&lt;/p&gt;&lt;p&gt;(2) Therefore, the only chance for a synchronous web client is if the call is running in a worker thread.&amp;nbsp; You can block the worker thread as you wish.&amp;nbsp; Just that somebody else needs to unblock your thread when it is done.&lt;/p&gt;&lt;p&gt;(3) To block/unblock, the best tool is ManualResetEvent.&amp;nbsp; To block, you do this:&lt;/p&gt;&lt;p&gt;&lt;font color="#6600ff" face="courier new,courier"&gt;ManualResetEvent m = new ManualResetEvent(false);&lt;br /&gt;...&lt;br /&gt;m.WaitOne();&lt;/font&gt;&lt;/p&gt;&lt;p&gt;To unblock, you do this:&lt;/p&gt;&lt;p&gt;&lt;font color="#6600ff" face="courier new,courier"&gt;m.Set();&lt;/font&gt;&lt;/p&gt;&lt;p&gt;(4) So to make a synchronous web client, you create ManualResetEvent, start the request from the background, block the thread with WaitOne(), and in the Completed event, unblock the thread.&amp;nbsp; Something like the following (not necessarily syntactically correct but the idea is here):&lt;/p&gt;&lt;p&gt;&lt;font color="#6600ff" face="courier new,courier"&gt;ManualResetEvent m = new ManualResetEvent(false);&lt;br /&gt;WebClient wc = new WebClient();&lt;br /&gt;wc.Completed += () =&amp;gt; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; ...&lt;br /&gt;&amp;nbsp;&amp;nbsp; m.Set();&lt;br /&gt;};&lt;br /&gt;wc.OpenRead(new Uri(uri), ...);&lt;br /&gt;m.WaitOne();&lt;/font&gt;&lt;/p&gt;&lt;p&gt;(5) You can abstract this into a SyncWebClient object, so you can do this:&lt;/p&gt;&lt;p&gt;&lt;font color="#6600ff" face="courier new,courier"&gt;SyncWebClient swc = new SyncWebClient();&lt;br /&gt;string result = swc.DownloadString(new Uri(uri), ...);&lt;/font&gt;&lt;/p&gt;&lt;p&gt;or this:&lt;/p&gt;&lt;p&gt;&lt;font color="#6600ff" face="courier new,courier"&gt;SyncWebClient swc = new SyncWebClient();&lt;br /&gt;Stream stream = swc.OpenRead(new Uri(uri), ...);&lt;/font&gt;&lt;/p&gt;&lt;p&gt;Again, the caveat is that &lt;font color="#660000"&gt;THIS CAN ONLY BE CALLED FROM A WORKER THREAD&lt;/font&gt;.&amp;nbsp; Keep this limitation in mind.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Prompts, Alerts, Dialogs, etc</title><link>http://forums.silverlight.net/forums/thread/242520.aspx</link><pubDate>Sat, 04 Jul 2009 13:35:29 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:242520</guid><dc:creator>maxima120</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/242520.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=35&amp;PostID=242520</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/silverlight/images/icon-quote.gif"&gt; &lt;strong&gt;ksleung:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;Actually I recently found a compromise, which is that if the business logic is running on the background thread, you can do things in a synchronous manner.&amp;nbsp; For example, I am now able to write code so that even WebClient can be executed synchronously.&lt;/div&gt;&lt;/BLOCKQUOTE&gt;I cant find this in your blog. Could you please provide link to the sample or the article?&lt;/p&gt;
&lt;p&gt;I tried to call business layer in separate thread synchronousliy but couldnt make it work. &lt;/p&gt;</description></item><item><title>Re: Prompts, Alerts, Dialogs, etc</title><link>http://forums.silverlight.net/forums/thread/230731.aspx</link><pubDate>Mon, 08 Jun 2009 21:45:09 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:230731</guid><dc:creator>ksleung</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/230731.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=35&amp;PostID=230731</wfw:commentRss><description>&lt;p&gt;I find that asynchronous code to be annoying when the logic is sequential.&amp;nbsp; However, we do want asychronous code since you really shouldn&amp;#39;t block the UI thread under most circumstances.&amp;nbsp; Heck, when the UI thread is blocked, even background WCF calls are blocked!&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Actually I recently found a compromise, which is that if the business logic is running on the background thread, you can do things in a synchronous manner.&amp;nbsp; For example, I am now able to write code so that even WebClient can be executed synchronously.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Prompts, Alerts, Dialogs, etc</title><link>http://forums.silverlight.net/forums/thread/230710.aspx</link><pubDate>Mon, 08 Jun 2009 21:07:20 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:230710</guid><dc:creator>acmilan5</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/230710.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=35&amp;PostID=230710</wfw:commentRss><description>&lt;p&gt;Hello.&amp;nbsp; Thank you for the pointer.&amp;nbsp; ChildWindow does indeed do the new window part but unfortunately it doesn&amp;#39;t address the problem of not being able to write linear code for the common scenario of prompting, alerts, etc.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;From a writeup on the new control:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;Another&amp;nbsp;aspect of&amp;nbsp;child windows that may not be obvious is that Show()
is an asynchronous call. That is, it doesn&amp;#39;t wait for the dialog to be
dismissed;&amp;nbsp;it returns immediately. That&amp;#39;s why Show() returns void
rather than a DialogResult. If you want to know how the dialog was
dismissed (that is, what the DialogResult value is once the dialog is
closed), you handle the dialog&amp;#39;s Closed event and check DialogResult
there.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;More asynchronicity and event handlers. :-(&amp;nbsp; Really makes for ugly, disjointed code in simple, common scenarios like prompting the user for a string value.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Prompts, Alerts, Dialogs, etc</title><link>http://forums.silverlight.net/forums/thread/230692.aspx</link><pubDate>Mon, 08 Jun 2009 20:02:07 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:230692</guid><dc:creator>pbromberg</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/230692.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=35&amp;PostID=230692</wfw:commentRss><description>&lt;p&gt;In Silverlight 3, ChildWindow does pretty much what you describe.&lt;/p&gt;</description></item><item><title>Prompts, Alerts, Dialogs, etc</title><link>http://forums.silverlight.net/forums/thread/230678.aspx</link><pubDate>Mon, 08 Jun 2009 19:19:39 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:230678</guid><dc:creator>acmilan5</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/230678.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=35&amp;PostID=230678</wfw:commentRss><description>&lt;p&gt;Is there something coming in SL 3 that makes it simpler to prompt the user for information.&amp;nbsp; e.g., The type of functionality that takes all of one line of code in javascript and other environments (e.g., prompt(&amp;quot;What&amp;#39;s your name?&amp;quot;) ) but isn&amp;#39;t possible in SL without rolling your own widget.&amp;nbsp; Even with a custom dialog, you&amp;#39;re not able to write linear code like &lt;/p&gt;&lt;p&gt;openDialog();&lt;br /&gt;doSomthingWithInformationEntered(); &lt;/p&gt;&lt;p&gt;since processing continues with doSomthingWithInformationEntered as soon as the dialog opens (not after it&amp;#39;s closed).&amp;nbsp; So instead, you have to write an event handlers for the various buttons that might be on the dialog.&amp;nbsp; Things get bloated and messy rather quickly. &lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>