Friday, June 6, 2014

Start may not be called on a promise-style task.

             Recently i have faced this issue . The problem here is  The await keyword inside your asynchronous method is trying to come back to the UI thread.Since the User Interface  thread is busy and waiting for the entire task to complete, you have a deadlock.Moving the async call to Task.Run() solves the issue.Because the async call is now running on a thread pool thread, it doesn't try to come back to the UI thread, and everything therefore works.

               Alternatively, you can call StartAsTask().ConfigureAwait(false) before awaiting the inner operation to make it come back to the thread pool rather than the UI thread, avoiding the deadlock entirely.

 

Here is the working code to avoid the above exception

  1: private void GetData(string text)
  2: {
  3:     var task = Task.Run(async () => { await GetDataAsync(sqlQuery); });
  4:     task.Wait();
  5: }
  6: 

Monday, June 2, 2014

Detecting the Browser using jQuery including IE 11

Recently  one of the team member got the issue with IE 11 while writing the code to detect the browser.The browser detection code what he has written is not working with IE 11 . The  issue here is Microsoft keep updating the User Agent String every time when new IE version released ..

To fix the issue i made few changes and now it is working .

Here is the code  to detect the browser including IE 11

<script  type="text/javascript" >
 
 function GetBrowserDetails() {
         var ua = window.navigator.userAgent
          var msie = ua.indexOf("MSIE ")
 
          // If Internet Explorer, return version number
          if (msie > 0)
          return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)))
 
            // If Internet Explorer 11 handling differently becaue UserAgent string updated by Microsoft
           else if (!!navigator.userAgent.match(/Trident\/7\./))
               return 11;
           else
           //If another browser just returning  0
             return 0
          }
       if (GetBrowserDetails() > 0)
        alert("Hey This is Internet Explorer and the version no is " + GetBrowserDetails());
       else
         alert("Hey This is not IE browser");
 
   </script>