<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://davidjberman.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>C sharp (C#)</title><link>http://davidjberman.com/blogs/csharp/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>How to detect a mobile web browser using ASP.NET 2.0</title><link>http://davidjberman.com/blogs/csharp/archive/2008/04/10/how-to-detect-a-mobile-web-browser-using-asp-net-2-0.aspx</link><pubDate>Thu, 10 Apr 2008 16:20:00 GMT</pubDate><guid isPermaLink="false">ecfba891-f940-4913-a10d-cc8fe6f9482a:322</guid><dc:creator>Dave</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://davidjberman.com/blogs/csharp/rsscomments.aspx?PostID=322</wfw:commentRss><comments>http://davidjberman.com/blogs/csharp/archive/2008/04/10/how-to-detect-a-mobile-web-browser-using-asp-net-2-0.aspx#comments</comments><description>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Today I&amp;#39;m using two mobile devices:&amp;nbsp; The BlackBerry Perl 8130 and
the BlackBerry 8830 &amp;#39;World Edition&amp;#39; phones by Verizion.&amp;nbsp; The 8830 is
larger but has a qwerty keyboard.&amp;nbsp; If I&amp;#39;m actually going to be sending
email from something, this is the choice.&amp;nbsp; For being in touch when on
the go (and I don&amp;#39;t like to carry lots of stuff) the Perl is good.&amp;nbsp; But
when I&amp;#39;m on the train or bored waiting for something, I like to use my
Perl to access some websites, especially my own.&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Both phones come with Research In Motion (RIM)&amp;#39;s built in
browser.&amp;nbsp; It supports images but it&amp;#39;s definitely a mobile browser.&amp;nbsp; It
is designed to display content that fits well on a phone screen. This
is a great interface for getting information quickly from mobile
optimized websites.&amp;nbsp; However, since mobile phones have limited screen
sizes and capabilities, a lot of what your website has to offer just
isn&amp;#39;t good in that environment.&amp;nbsp; &lt;a href="http://www.operamini.com/" title="Opera Mini MObile Browser" target="_blank"&gt;Opera Mini&lt;/a&gt;
is great, it runs on both devices (and many other compatible devices)
and shows you the full web page, which it shrinks down to fit your
screen.&amp;nbsp; You can zoom in on any part of the page and interact with
content that doesn&amp;#39;t have special mobile-enabled programming.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Mobile phone bandwidth is increasing all the time, and mobile
device web browsers keep improving, but you don&amp;#39;t want to serve full
javascript enabled, multi-media data to a mobile device; it&amp;#39;s too slow,
and many features won&amp;#39;t work.&amp;nbsp; You know this, which is why you&amp;#39;re
reading this blog post.&amp;nbsp; So if you are an ASP.NET programmer, how do
you detect if the visitor is using a mobile browser?&amp;nbsp;&lt;/p&gt;&lt;p&gt;.NET Framework to the rescue:&lt;/p&gt;&lt;p&gt;HttpContext.Current.Request.Browser will give you a HttpBrowserCapabilities object, which has a property &lt;b&gt;IsMobileDevice&lt;/b&gt;.&amp;nbsp;
The value of this property will be true if a mobile browser is
detected.&amp;nbsp; This method is looking at the http post headers which
disclose the browser and platform information of the device.&amp;nbsp; You could
check these values yourself, but having access to this property is a
lot easier.&amp;nbsp; Be warned, it doesn&amp;#39;t always work because new devices keep
coming out and not every browser brand name is recognized.&amp;nbsp; Here is a
list of officially recognized browsers:&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.asp.net/mobile/tested-devices/" title="Compatible Mobile  Browsers" target="_blank"&gt;http://www.asp.net/mobile/tested-devices/&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;For
some additional information on detecting mobile browsers that are not
compatible, and some sample code on how to use both methods, check out
this link:&lt;/p&gt;&lt;p&gt;&lt;a href="http://forums.asp.net/p/474014/1162577.aspx" title="More info on browser detection" target="_blank"&gt;http://forums.asp.net/p/474014/1162577.aspx&lt;/a&gt;&lt;br /&gt;&amp;nbsp;
&lt;br /&gt;&lt;/p&gt;&lt;img src="http://davidjberman.com/aggbug.aspx?PostID=322" width="1" height="1"&gt;</description><category domain="http://davidjberman.com/blogs/csharp/archive/tags/ASP.NET+BlackBerry/default.aspx">ASP.NET BlackBerry</category></item><item><title>Optimizing your ASP.NET 2.0 website performance</title><link>http://davidjberman.com/blogs/csharp/archive/2008/04/10/optimizing-your-asp-net-2-0-website-performance.aspx</link><pubDate>Thu, 10 Apr 2008 16:05:00 GMT</pubDate><guid isPermaLink="false">ecfba891-f940-4913-a10d-cc8fe6f9482a:321</guid><dc:creator>Dave</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://davidjberman.com/blogs/csharp/rsscomments.aspx?PostID=321</wfw:commentRss><comments>http://davidjberman.com/blogs/csharp/archive/2008/04/10/optimizing-your-asp-net-2-0-website-performance.aspx#comments</comments><description>&lt;p&gt;I just discovered this great article on &lt;a href="http://www.codeproject.com" title="The Code Project" target="_blank"&gt;codeproject.com&lt;/a&gt; for optimizing ASP.NET 2.0 website performance:&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.codeproject.com/KB/aspnet/10ASPNetPerformance.aspx" title="10 ASP.NET Performance and Scalability Secrets" target="_blank"&gt;http://www.codeproject.com/KB/aspnet/10ASPNetPerformance.aspx&lt;/a&gt; by Omar Al Zabir titled &lt;u&gt;10 ASP.NET Performance and Scalability Secrets&lt;/u&gt;&lt;b&gt;.&lt;/b&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I wanted to pin it on my blog so this article doesn&amp;#39;t get missed.&amp;nbsp; There is some good practical information here on how to tweak your ASP.NET configuration for improved performance.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://davidjberman.com/aggbug.aspx?PostID=321" width="1" height="1"&gt;</description><category domain="http://davidjberman.com/blogs/csharp/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>How to create asynchronous ASP.NET pages using C#</title><link>http://davidjberman.com/blogs/csharp/archive/2007/08/13/how-to-create-asynchronous-asp-net-pages-using-c.aspx</link><pubDate>Mon, 13 Aug 2007 18:13:00 GMT</pubDate><guid isPermaLink="false">ecfba891-f940-4913-a10d-cc8fe6f9482a:315</guid><dc:creator>Dave</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://davidjberman.com/blogs/csharp/rsscomments.aspx?PostID=315</wfw:commentRss><comments>http://davidjberman.com/blogs/csharp/archive/2007/08/13/how-to-create-asynchronous-asp-net-pages-using-c.aspx#comments</comments><description>&lt;p&gt;IIS combined with ASP.NET provides many technologies to improve performance and scalability.&amp;nbsp; IIS provides a pool of threads so that it can server many requests simultaneously.&amp;nbsp; The pool has a limited number of threads in it, and once they are used up additional requests can start to pile up.&amp;nbsp; Keeping the total number of active threads down is an attempt to prevent too many active threads from consuming all of the available CPU time.&amp;nbsp; However, with today&amp;#39;s data intensive websites, much of the time threads are tied up waiting for an external resource such as a request from a web service or from a database.&amp;nbsp; Asynchronous pages in ASP.NET can boost performance in these situations by enabling threads in the pool to be used to serve additional requests while an operation is waiting for an external resource request to complete.&lt;/p&gt;
&lt;p&gt;Suppose you have a website with two web pages.&amp;nbsp; One is your home page which display&amp;#39;s a greeting, and the second page displays a large dataset from a database.&amp;nbsp;&amp;nbsp;You have 25 threads in your thread pool.&amp;nbsp; 25 people simultaneously are accessing the database query page, and one additional person comes onto the site to see the home page which has static content on it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Compare these two scenarios:&lt;/p&gt;
&lt;p&gt;Synchronous database driven page:&amp;nbsp; While everyone is waiting for the dataset to load, all available threads are in use so the 26&lt;sup&gt;th&lt;/sup&gt; request for the home page becomes blocked.&lt;/p&gt;
&lt;p&gt;Asynchronous database driven page: &amp;nbsp;While 25 requests are waiting for data from the database, those threads are returned to the pool for work.&amp;nbsp; When the 26&lt;sup&gt;th&lt;/sup&gt; request comes in for the home page, that page is returned immediately.&amp;nbsp; As the datasets are returned the threads are drawn out of the thread pool to finish serving the pages.&amp;nbsp; The result is that the threads spend much more time available to serve requests.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here are two good pages for getting started with asynchronous ASP.NET pages:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Asynchronous ASP.NET Page Processing by Peter Bromberg&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.eggheadcafe.com/articles/20060918.asp"&gt;http://www.eggheadcafe.com/articles/20060918.asp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Use Threads and Build Asynchronous Handlers in Your Server-Side Web Code by Fritz Onion&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/03/06/threading/default.aspx"&gt;http://msdn.microsoft.com/msdnmag/issues/03/06/threading/default.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After reading these and some other articles, here is a piece of code to get you started.&amp;nbsp; I put this together to process a job in the background as a generic pattern.&amp;nbsp; I wrap my big job in a delegate so that I can get an IAsyncResult object back.&amp;nbsp; This simplifies things, because in most examples I read you get this by calling a web service asynchronously but this isn&amp;#39;t always what you want done.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Step 1: &amp;nbsp;Make an empty asp.net page.&amp;nbsp; Add &lt;b&gt;async=&amp;quot;true&amp;quot; &lt;/b&gt;to the @Page tag in the .aspx file.&lt;/p&gt;
&lt;p&gt;Step 2: &amp;nbsp;In the class code, declare a delegate&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;public delegate void AsyncTaskDelegate();&lt;/p&gt;
&lt;p&gt;Step 3: &amp;nbsp;Declare a member variable in the class to prevent the delegate from going out of scope&lt;/p&gt;
&lt;p&gt;&amp;nbsp;AsyncTaskDelegate _runnerDelegate = null;&lt;/p&gt;
&lt;p&gt;Step 4:&amp;nbsp; Create a method that will be run asynchronously:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;public void DoJob()&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; this.GridView1.DataSource = GetDatasetFromDatabase();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.GridView1.DataBind();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;Step 5:&amp;nbsp; Tell the framework you want your job run.&amp;nbsp; You can put this in Page_Load or in a response to a button click / postback:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Register async methods&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AddOnPreRenderCompleteAsync(&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new BeginEventHandler(OnBegin),&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new EndEventHandler(OnEnd)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/p&gt;
&lt;p&gt;Step 6: &amp;nbsp;Add the event to kick off the delegate and run the job asynchronously.&lt;/p&gt;
&lt;p&gt;IAsyncResult OnBegin(object sender, EventArgs e, AsyncCallback cb, object state)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _runnerDelegate = new AsyncTaskDelegate(this.DoJob);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IAsyncResult result = _runnerDelegate.BeginInvoke(cb, state);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Step 7: &amp;nbsp;&amp;nbsp;Add an event handler for after the request finishes &lt;/p&gt;
&lt;p&gt;void OnEnd(IAsyncResult ar)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _runnerDelegate.EndInvoke(ar);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;All together, it looks like this:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;public partial class Async : System.Web.UI.Page&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public delegate void AsyncTaskDelegate();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AsyncTaskDelegate _runnerDelegate = null;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IAsyncResult OnBegin(object sender, EventArgs e, &lt;/p&gt;
&lt;p&gt;AsyncCallback cb, object state)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _runnerDelegate = new AsyncTaskDelegate(this.DoJob);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IAsyncResult result = _runnerDelegate.BeginInvoke(cb, state);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void DoJob()&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;this.GridView1.DataSource = new AsyncTaskDelegate(this.DoJob);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; this.GridView1.DataBind();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void OnEnd(IAsyncResult ar)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _runnerDelegate.EndInvoke(ar);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected void Button1_Click(object sender, EventArgs e)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Register async methods&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AddOnPreRenderCompleteAsync(&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new BeginEventHandler(OnBegin),&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new EndEventHandler(OnEnd)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;img src="http://davidjberman.com/aggbug.aspx?PostID=315" width="1" height="1"&gt;</description><category domain="http://davidjberman.com/blogs/csharp/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://davidjberman.com/blogs/csharp/archive/tags/Programming/default.aspx">Programming</category><category domain="http://davidjberman.com/blogs/csharp/archive/tags/ASP.NET/default.aspx">ASP.NET</category></item><item><title>How to create a console window for a Windows Forms application</title><link>http://davidjberman.com/blogs/csharp/archive/2007/08/06/how-to-create-a-console-window-for-a-windows-forms-application.aspx</link><pubDate>Mon, 06 Aug 2007 20:38:00 GMT</pubDate><guid isPermaLink="false">ecfba891-f940-4913-a10d-cc8fe6f9482a:314</guid><dc:creator>Dave</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://davidjberman.com/blogs/csharp/rsscomments.aspx?PostID=314</wfw:commentRss><comments>http://davidjberman.com/blogs/csharp/archive/2007/08/06/how-to-create-a-console-window-for-a-windows-forms-application.aspx#comments</comments><description>&lt;p&gt;Suppose you are writing a GUI application for Windows and you want to be able to debug your applicaiton by sending console output to a console window that opens only if you pass a certain command line argument or are compiled in debug mode.&amp;nbsp; Console.WriteLine sends your output to nowhere very fast.&amp;nbsp; If you want to have a console window, here is how you do it:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Inside one of your classes insert this reference to the AllocConsole method in kernel32.dll:&lt;/p&gt;
&lt;p&gt;[DllImport(&amp;quot;kernel32.dll&amp;quot;)]&lt;br /&gt;public static extern Int32 AllocConsole();&lt;/p&gt;
&lt;p&gt;Now just call MyClass.AllocConsole() if you want a console for output and voila, there you go!&amp;nbsp; All output to Console now appears in your console window.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://davidjberman.com/aggbug.aspx?PostID=314" width="1" height="1"&gt;</description><category domain="http://davidjberman.com/blogs/csharp/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>How to access command line arguments</title><link>http://davidjberman.com/blogs/csharp/archive/2007/08/06/how-to-access-command-line-arguments.aspx</link><pubDate>Mon, 06 Aug 2007 20:32:00 GMT</pubDate><guid isPermaLink="false">ecfba891-f940-4913-a10d-cc8fe6f9482a:313</guid><dc:creator>Dave</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://davidjberman.com/blogs/csharp/rsscomments.aspx?PostID=313</wfw:commentRss><comments>http://davidjberman.com/blogs/csharp/archive/2007/08/06/how-to-access-command-line-arguments.aspx#comments</comments><description>&lt;p&gt;In a C# Windows Application or Console Application, you may want to access arguments passed to your application via the Command Line.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;This is actually very easy to do.&amp;nbsp; All you have to do is modify your Main() method to take in an array of strings:&lt;/p&gt;&amp;nbsp;&lt;strong&gt;static void Main(string[] args)&lt;/strong&gt; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach(string arg in args)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Console.WriteLine(String.Format(&amp;quot;Arg: {0}&amp;quot;, arg);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp; }&lt;img src="http://davidjberman.com/aggbug.aspx?PostID=313" width="1" height="1"&gt;</description><category domain="http://davidjberman.com/blogs/csharp/archive/tags/C_2300_/default.aspx">C#</category></item></channel></rss>