<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/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>Peter Ritchie's MVP Blog - All Comments</title><link>http://msmvps.com/blogs/peterritchie/default.aspx</link><description>This is not a life-saving device.</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>re: Thread.Sleep is a sign of a poorly designed program.</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/04/26/thread-sleep-is-a-sign-of-a-poorly-designed-program.aspx#1748074</link><pubDate>Tue, 29 Dec 2009 05:07:02 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1748074</guid><dc:creator>mnjrupp</dc:creator><description>&lt;p&gt;I use Thread.Sleep with the .Net ThreadPool in a c++ CLI winform app. I don&amp;#39;t have the luxury of the console so a textbox created from the main UI to simulate console I/O on separate threads is the only alternative I can see. &lt;/p&gt;
&lt;p&gt;The threadpool does a great job of keeping tabs on the threads created. Of course I have to Invoke a delegate to communicate with the textbox as well. There is the nasty Exception of cross threading if I don&amp;#39;t use seperate threads and a delegate.&lt;/p&gt;
&lt;p&gt; Anyone have a better idea. I&amp;#39;m all ears.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1748074" width="1" height="1"&gt;</description></item><item><title>re: Using Toolbox for Code Snippets in Visual Studio 2005</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/Using-Toolbox-for-Code-Snippets-in-Visual-Studio-2005.aspx#1746493</link><pubDate>Fri, 18 Dec 2009 22:11:06 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1746493</guid><dc:creator>Joe</dc:creator><description>&lt;p&gt;This doesn&amp;#39;t seem to work for .sql files. Any suggestions?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1746493" width="1" height="1"&gt;</description></item><item><title>re: Windows Live Messenger Virus Scanner Settings</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/03/22/windows-live-messenger-virus-scanner-settings.aspx#1746463</link><pubDate>Fri, 18 Dec 2009 19:07:24 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1746463</guid><dc:creator>ICEMAN</dc:creator><description>&lt;p&gt;dude you are the man&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1746463" width="1" height="1"&gt;</description></item><item><title>re: DataContractSerializer.ReadObject is easily confused.</title><link>http://msmvps.com/blogs/peterritchie/archive/2009/04/29/datacontractserializer-readobject-is-easily-confused.aspx#1745984</link><pubDate>Wed, 16 Dec 2009 17:27:13 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1745984</guid><dc:creator>Ostati</dc:creator><description>&lt;p&gt;This is what I&amp;#39;m using and it works!&lt;/p&gt;
&lt;p&gt;public static string SerializeDataContract&amp;lt;TModel&amp;gt;(TModel dataContract)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;var serializer = new DataContractSerializer(typeof(TModel));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;using (var stream = new MemoryStream())&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;serializer.WriteObject(stream, dataContract);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;stream.Position = 0L;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return Encoding.UTF8.GetString(stream.ToArray());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1745984" width="1" height="1"&gt;</description></item><item><title>re: DataContractSerializer.ReadObject is easily confused.</title><link>http://msmvps.com/blogs/peterritchie/archive/2009/04/29/datacontractserializer-readobject-is-easily-confused.aspx#1745504</link><pubDate>Mon, 14 Dec 2009 12:35:02 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1745504</guid><dc:creator>Jesse Houwing</dc:creator><description>&lt;p&gt;Setting the position to 0 in the memorystream after writing the data and then using a StreamReader to read the data from the memorystream works great as well. I find it more readable... (and it defaults to unicode)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1745504" width="1" height="1"&gt;</description></item><item><title>re: Using Toolbox for Code Snippets in Visual Studio 2005</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/Using-Toolbox-for-Code-Snippets-in-Visual-Studio-2005.aspx#1744499</link><pubDate>Wed, 09 Dec 2009 22:10:03 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1744499</guid><dc:creator>Chi</dc:creator><description>&lt;p&gt;&amp;quot;...every time I copy code snippets it automatically adds it into the toolbox...&amp;quot;&lt;/p&gt;
&lt;p&gt;I have the same problem... anyone knows how to turn it off please?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1744499" width="1" height="1"&gt;</description></item><item><title>re: Sudden "...you must have Terminal Server User Access permissions on this computer." Error.</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/02/03/sudden-you-must-have-terminal-server-user-access-permissions-on-this-computer-error.aspx#1744111</link><pubDate>Mon, 07 Dec 2009 17:04:29 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1744111</guid><dc:creator>Hans</dc:creator><description>&lt;p&gt;Thanks! That was I need! :-)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1744111" width="1" height="1"&gt;</description></item><item><title>re: Sudden "...you must have Terminal Server User Access permissions on this computer." Error.</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/02/03/sudden-you-must-have-terminal-server-user-access-permissions-on-this-computer-error.aspx#1744079</link><pubDate>Mon, 07 Dec 2009 12:55:37 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1744079</guid><dc:creator>gIRISH</dc:creator><description>&lt;p&gt;gRATE DUDE IT REALLY WORKS THANKS A LOT.........&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1744079" width="1" height="1"&gt;</description></item><item><title>re: Windows Live Messenger Virus Scanner Settings</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/03/22/windows-live-messenger-virus-scanner-settings.aspx#1743154</link><pubDate>Tue, 01 Dec 2009 08:24:25 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1743154</guid><dc:creator>Mister</dc:creator><description>&lt;p&gt;&amp;quot;C:\Program Files\Symantec AntiVirus\Rtvscan.exe&amp;quot; &amp;nbsp;/selfcheck+ /list+ /scroll+ /quit+ /pattern+ /heur+ /scanfile+ /scanboot- /scanmbr- /scanmem- /arch+ /sfx+ /pack+ /mailbox- /adware /unsafe /ah /prompt /all&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1743154" width="1" height="1"&gt;</description></item><item><title>re: Fundamentals of Object-Oriented Design (OOD) Part 1</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/05/01/fundamentals-of-object-oriented-design-ood-part-1.aspx#1742284</link><pubDate>Thu, 26 Nov 2009 13:47:48 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1742284</guid><dc:creator>Raj</dc:creator><description>&lt;p&gt;great buddy nice helpfull article need more on Design patterns&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1742284" width="1" height="1"&gt;</description></item><item><title>re: Thread.Sleep is a sign of a poorly designed program.</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/04/26/thread-sleep-is-a-sign-of-a-poorly-designed-program.aspx#1741766</link><pubDate>Mon, 23 Nov 2009 16:22:30 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1741766</guid><dc:creator>Fred</dc:creator><description>&lt;p&gt;Thanks for the tip, I didn&amp;#39;t know that.&lt;/p&gt;
&lt;p&gt;In fact, the MSDN doc about the Sleep method is pretty unfair :&lt;/p&gt;
&lt;p&gt;&amp;quot;The number of milliseconds for which the thread is blocked.&amp;quot;&lt;/p&gt;
&lt;p&gt;So from now I will use the System.Threading.Timer class instead...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1741766" width="1" height="1"&gt;</description></item><item><title>re: Sudden "...you must have Terminal Server User Access permissions on this computer." Error.</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/02/03/sudden-you-must-have-terminal-server-user-access-permissions-on-this-computer-error.aspx#1740991</link><pubDate>Fri, 20 Nov 2009 13:08:04 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1740991</guid><dc:creator>Davide</dc:creator><description>&lt;p&gt;Thx a lot: this is the only way I found to solve my problem!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1740991" width="1" height="1"&gt;</description></item><item><title>re: Thread.Sleep is a sign of a poorly designed program.</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/04/26/thread-sleep-is-a-sign-of-a-poorly-designed-program.aspx#1739735</link><pubDate>Sat, 14 Nov 2009 13:56:21 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1739735</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;@Richard. &amp;nbsp;Right, using Thread.Sleep(1) will allow any other thread to take control of the CPU for at least a time-slice.&lt;/p&gt;
&lt;p&gt;The question is a little misguided. &amp;nbsp;The parameter to Sleep is the number of milliseconds to sleep. &amp;nbsp;The fact that we&amp;#39;re using 1 millisecond as a parameter means it&amp;#39;s *really* difficult for any number of threads to be calling Thread.Sleep at the very same time. &amp;nbsp;Then, there&amp;#39;s the fact that only one thread at a time per processor is actually running...&lt;/p&gt;
&lt;p&gt;Your question suggests to me that you want to dip into thread prioritization. &amp;nbsp;You want to periodically do no work so other applications can do some. &amp;nbsp;But, you don&amp;#39;t know what those other applications do or whether stopping your work will benefit them at all. &amp;nbsp;I wouldn&amp;#39;t suggest writing your application to do this; there&amp;#39;s no way to do it correctly without being the operating system. &amp;nbsp;Using Thread.Sleep(1) in your threads is enough for the operating system to allow other threads to be responsive. &amp;nbsp;It works remarkably well.&lt;/p&gt;
&lt;p&gt;Are you using Thread.Sleep(1) and seeing that other applications are being starved of CPU?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1739735" width="1" height="1"&gt;</description></item><item><title>re: Thread.Sleep is a sign of a poorly designed program.</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/04/26/thread-sleep-is-a-sign-of-a-poorly-designed-program.aspx#1739682</link><pubDate>Sat, 14 Nov 2009 08:51:32 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1739682</guid><dc:creator>Richard</dc:creator><description>&lt;p&gt;We are looking for a way to relinquish CPU cycles to other applications in a milti-threaded application. If we use sleep.thread(1) in each thread then my assumption is that our other threads will take the CPU.&lt;/p&gt;
&lt;p&gt;The question is...how can we use thread.sleep(1) on all of our threads simultaneously so that CPU cycles are open for other applications?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1739682" width="1" height="1"&gt;</description></item><item><title>re: Upcoming C# 3 Guidance From Microsoft</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/03/13/upcoming-c-3-guidance-from-microsoft.aspx#1737635</link><pubDate>Wed, 04 Nov 2009 15:38:46 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1737635</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;@Lijo: I don&amp;#39;t know of any books that specifically associating language features to SOLID principles. &amp;nbsp;There&amp;#39;s a couple of books that have information about SOLID principles (among other things) and C#. &amp;nbsp;Some of the principles would inherently require specific language features (like DI and Generics):&lt;/p&gt;
&lt;p&gt;Robert/Micha Martin&amp;#39;s Agile Practices and Patterns in C#: &lt;a rel="nofollow" target="_new" href="http://www.amazon.ca/Agile-Principles-Patterns-Practices-C/dp/0131857258"&gt;www.amazon.ca/.../0131857258&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Karl Seguin&amp;#39;s free Foundations of Programming eBook: &lt;a rel="nofollow" target="_new" href="http://bit.ly/2BWCfd"&gt;http://bit.ly/2BWCfd&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1737635" width="1" height="1"&gt;</description></item><item><title>re: Upcoming C# 3 Guidance From Microsoft</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/03/13/upcoming-c-3-guidance-from-microsoft.aspx#1737616</link><pubDate>Wed, 04 Nov 2009 13:47:37 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1737616</guid><dc:creator>Lijo</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you please let me know whether there is any C# 3 book available that explains about how to implement SOLID principles (Open Closed Principle,DI,Likosov, etc) using language features like GENERICS, LINQ, Lambda Expression,etc.&lt;/p&gt;
&lt;p&gt;--Sorry if it is a wrong place to ask this question as this is a deviation from the topic.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Lijo Cheeran Joseph&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1737616" width="1" height="1"&gt;</description></item><item><title>re: "Object is currently in use elsewhere" error.</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/01/28/quot-object-is-currently-in-use-elsewhere-quot-error.aspx#1733756</link><pubDate>Tue, 20 Oct 2009 21:16:44 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1733756</guid><dc:creator>PeterRitchie</dc:creator><description>&lt;p&gt;@AlanB: GDI+ (the underlying Windows library that Graphics uses) is not thread safe. &amp;nbsp;Adding a Sleep() call like that, as you&amp;#39;ve noticed, simply slows down your code and reduces the likelihood of having another exception because it simply re-tries that code that failed and it&amp;#39;s less likely that another conflicting GDI+ call is being made at the very same time on another thread.&lt;/p&gt;
&lt;p&gt;This isn&amp;#39;t a solution. &amp;nbsp;Since GDI+ isn&amp;#39;t thread-safe you need to synchronize calls to GDI+ on multiple threads. &amp;nbsp;This simply means having a shared lock object and using the C# lock keyword where ever you perform GDI+ operations (i.e. around acquisition of a resource and disposal of the resource).&lt;/p&gt;
&lt;p&gt;Since you code isn&amp;#39;t the only code that can perform GDI+ operations you can&amp;#39;t synchronize all GDI+ code like this. &amp;nbsp;This leaves you to marshal the code back to the GUI thread--which is a drastic design change from what you&amp;#39;ve got now.&lt;/p&gt;
&lt;p&gt;Long story short: you can&amp;#39;t perform GDI+ operations reliably on any thread other than the main (GUI) thread.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1733756" width="1" height="1"&gt;</description></item><item><title>"Object is currently in use elsewhere" a workaround</title><link>http://msmvps.com/blogs/peterritchie/archive/2008/01/28/quot-object-is-currently-in-use-elsewhere-quot-error.aspx#1733733</link><pubDate>Tue, 20 Oct 2009 19:29:19 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1733733</guid><dc:creator>Alan8</dc:creator><description>&lt;p&gt;I&amp;#39;ve been getting this error since I moved some graphics code to a background thread.&lt;/p&gt;
&lt;p&gt;Every Graphics.FromImage () had a matching Dispose () call, so that wasn&amp;#39;t the problem.&lt;/p&gt;
&lt;p&gt;It was happening in the Graphics.DrawImage () method. &amp;nbsp;But only the first time.&lt;/p&gt;
&lt;p&gt;So I put a try/catch block around the DrawImage () call, and a Thread.Sleep (5) in the catch block before trying the DrawImage () a second time. &amp;nbsp;This worked. &amp;nbsp;Sleep parameters &amp;lt;= 3 ms didn&amp;#39;t work.&lt;/p&gt;
&lt;p&gt;There&amp;#39;s a noticeable pause when this happens, which suggests it&amp;#39;s a Microsoft/.NET threading problem. &amp;nbsp;Maybe it will go away in a later version of .NET.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1733733" width="1" height="1"&gt;</description></item><item><title>re: Sudden "...you must have Terminal Server User Access permissions on this computer." Error.</title><link>http://msmvps.com/blogs/peterritchie/archive/2007/02/03/sudden-you-must-have-terminal-server-user-access-permissions-on-this-computer-error.aspx#1733378</link><pubDate>Mon, 19 Oct 2009 13:53:25 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1733378</guid><dc:creator>Xaj007</dc:creator><description>&lt;p&gt;Big big Thanks!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1733378" width="1" height="1"&gt;</description></item><item><title>re: Using Toolbox for Code Snippets in Visual Studio 2005</title><link>http://msmvps.com/blogs/peterritchie/archive/2006/10/13/Using-Toolbox-for-Code-Snippets-in-Visual-Studio-2005.aspx#1732066</link><pubDate>Tue, 13 Oct 2009 00:15:28 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1732066</guid><dc:creator>Serdar Osman Onur</dc:creator><description>&lt;p&gt;nice feature, i was looking for this...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1732066" width="1" height="1"&gt;</description></item></channel></rss>