Monday, August 18, 2014

Debugging Threads with Concurrency Visualizer

Features of Concurrency Visualizer:

  • Shift+Alt+F5
  • Fast processing, faster loading
           o Supports big traces
  • Supports big traces
  • Support s EventSource and custom markers
            o Built-in support for TPL, PLINQ, Sync Data Structures, and Dataflow
            o Built-in support for your own EventSource types
                    § Also provides Visual Studio markers API
  • New Visualizations
             o e.g. defender view

Demo:

Here are few steps to know that how to utilize “Concurrency Visualizer” for multithreaded applications.

  1. Create a Console project.
  2. Create custom EventSource to trace in the visualizer as below:
    [EventSource(Guid = "7BBB4E52-7DA7-45EB-B6C2-C01D460A087C")]
    class MyEventSource : EventSource
    {
    internal static MyEventSource log = new MyEventSource();

    [Event(1)]
    public void SomeEventHandled(int data)
    {
    WriteEvent(1, data);
    }
    }

    To provide GUID to the event source use “guidgen” and copy newly generated GUID. Then put it in the attribute of the EventSource class.

    clip_image002
  3. Now complete the test code to proceed the demo.

    Full code snippet:

    using System.Threading;
    using System.Threading.Tasks;

    namespace ConcurrencyVisualizerDemo
    {
    class Program
    {
    static void Main(string[] args)
    {
    var list = new List<Task>();
    for (int i = 0; i < 10; i++)
    {
    list.Add(Task.Run(() =>
    {
    //Loging here
    MyEventSource.log.SomeEventHandled(21);
    Thread.SpinWait(1000000);
    }));
    }
    Task.WaitAll(list.ToArray());
    }

    [EventSource(Guid = "7BBB4E52-7DA7-45EB-B6C2-C01D460A087C")]
    class MyEventSource : EventSource
    {
    internal static MyEventSource log = new MyEventSource();

    [Event(1)]
    public void SomeEventHandled(int data)
    {
    WriteEvent(1, data);
    }
    }
    }
    }


  4. There is optional extension “Concurrency Visualizer” for visual studio, which visual all the data to debug the concurrency between the treads. After installing this, you can find the option under Analyze menu. See image below:

    clip_image004
  5. Now copy the GUID  of MyEventSource and go to the Concurrency Visualizer’s settings. Then add new provider and put this copied guid in the provider.
    Analyze->Concurrency Visualizer->Advance Settings->Markers

    image

    Provide name and paste copied guid in the Privider GUID field. Click ok to complete provider addition.
  6. Now start Concurrency Visualizer by pressing Shift+Alt+F5 and it will start Shift+Alt+F5. Now it will start generating reports. See the below images:

    image

    image

    image

    image



Tuesday, April 15, 2014

How does === means different than == in JavaScript?

These two operators do not mean the same and does different operation too.
== verifies if the compared values are equal
=== verifies if the variables that are compared have the same value and are the same type
JavaScript's standard equality operators (== and !=) check if two expressions are equal (or not equal). If the two operands are not of the same type, JavaScript attempts to convert the operands to an appropriate type for the comparison. Values are considered equal if they are identical strings, numerically equivalent numbers, the same object, identical Boolean values, or (if different types) they can be coerced into one of these situations.
JavaScript's identity (strict equality) operators (=== and !==) behave identically to the equality operators except no type conversion is done, and the types must be the same to be considered equal. Here are a few examples:
"3" == 3 // true
"3" === 3 // false
1 == true // true
1 === true // false
"1" == true // true
"1" === true // false

Code snippet:

<script type="text/javascript">
   var a = 5;
   var b = '5';
   var c = 5;
   if(a==b)
   {
      document.write('a and b have the same value');
   }

   if(a===b)
   {
      document.write('a and b have the same value and the same type');
   }
   if(a===c)
   {
      document.write('a and c have the same value and the same type');
   }
</script>


Saturday, April 12, 2014

Use your Windows Phone 7 device as a portable

A simple registry edit turns your WP7 device into a USB drive.

Open the Registry Editor (regedit), go to HKEY_LOCAL_MACHINE\SYSTEM and then expand the CurrentControlSet\Enum\USB folder.

Search for PortableDeviceNameSpaceExcludeFromShell and there you will get the other setting which are need to set are below:

> Change ShowInShell from 0 to 1.
> Change PortableDeviceNameSpaceExcludeFromShell from 1 to 0.
> Change EnableLegacySupport from 0 to 1. That's it. If there's more than one Windows Phone 7 device listed.

Cheers! Now all done.

Note: Remember to take backup before doing any registry changes..

Tuesday, January 21, 2014

How to troubleshot Windows - References



it’s often helpful to repair the MBR (Master Boot Record) to restore the Windows 7 boot loader—and you can do it easily from the Windows installation disc.


Repairing the Master Boot Record
If you want to restore the master boot record, you can simply type in the following command:
bootrec /fixmbr
You can also write a new boot sector onto the system partition with this command (which is often more useful):
bootrec /fixboot

And of course, if you just use bootrec /? you’ll be able to see all the options.