Posts

Showing posts from February, 2014

Overwriting the same line on a C# Console

This is a good one which is very useful: for ( int i = 0 ; i < 100 ; ++ i ) { Console . Write ( "\r{0}" , i ); } http://stackoverflow.com/questions/888533/how-can-i-update-the-current-line-in-a-c-sharp-windows-console-app

How to handle application crash in code and do cleanup/ save state

AppDomain .CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; private   void  CurrentDomain_UnhandledException( object  sender,  UnhandledExceptionEventArgs  e)         {              Exception  ex = e.ExceptionObject  as   Exception ;              if  (ex !=  null )             {                  //Log error             }              if  (e.IsTerminating)             {       ...

PC slow for no reason?

I just found there is significant difference especially when running a server, if you change the power options from balanced to high performance. This is especially when your server is hyper-v and has VMs.

jQuery Mobile ASP.NET Gotcha

I have been working on jQuery Mobile recently. Specifically the feature where new pages are loaded in the background via AJAX calls. It is tricky to get everything working properly with ASP.NET AJAX and multiple ASP.NET pages. The point to remember is that jQuery Mobile "pages" are really the areas we mark as page in the HTML. So, when it loads the next "page" in the background, you don't get what you would normally expect - i.e., you only get the stuff inside the jQuery Mobile page. What this means is that: 1. All Javascript files have to be referenced in all pages. 2. All web service ASP.NET references have to be referenced in all pages. 3. Make sure that Javascript used for one page does not clash with that of other pages. When I was initially working on the pages, why something did not work simply made no sense. Then it started making sense in an intuitive manner which I liked a lot.

Metro Apps not Working? - No wonder nobody likes Windows 8

Took months for them to come out with this workaround: http://social.technet.microsoft.com/Forums/windows/en-US/6f119828-dd1b-42da-b8b5-c6e6c0d5617c/no-apps-or-windows-store-work-after-upgrading-to-windows-81-enterprise?forum=w8itproinstall As I had to do this all over again, here are the steps: The following finally fixed all issues for me (Store and all apps broken with black X, can't access PC Settings): 1) Fixing the app store:   1. Open registry editor typing regedit.exe from a command line.   2. Browse to the registry key at HKEY_CURRENT_USER\Software\Classes\Local Settings\software\microsoft\windows\currentversion\appmodel\repository\packages.   3. Right click on the “packages” key and bring up the “Permissions” tab.   4. Click the “Advanced” button located at the bottom right corner.   5. Check to see the account name that shows up as the “Owner” (this is the first line of text on the “advanced security settin...

Using jQuery Mobile with ASP.NET generating Javascript on server

If you are using jQuery Mobile which does downloads the next page via AJAX instead of via the browser, note that the Javascript still runs within the scope of the first page you loaded. So, use different variable names for the JS for different pages, and also the script which gets generated into the web page needs to go into the jQuery Mobile header, footer or content - otherwise it will not get loaded when the AJAX call retrieves the next page. I really like jQuery Mobile a lot because it takes away the pain of building mobile UIs in HTML5 [Update] I have been trying to debug a very difficult issue for the past few days and yesterday night I finally figured out - the reason why my AJAX call was not updating the content list on a different page than what I initially loaded is because each page needs to have content lists with different ids. If the ids are the same, then the code to clear and add items to the content list do not go to the correct content list.

Use Linq to update items in a list without using a for loop!

class   Program     {          public   class   MyEntity           {              public   int  property1;              public   int  property2;              public   int  property3;         }          static   void  Main( string [] args)         {              List < MyEntity > entities =  new   List < MyEntity >();             entities.Add( new   MyEntity () {...