Author Archives: Angel Kaushish

jQuery AJAX file upload from html5 canvas – not working via AJAX POST

Published by:

If your code is right and you are using something like this:

var imgUrlCanvas= document.getElementById(“canvas”).toDataURL(“image/png”);
imgUrlCanvas = imgUrlCanvas.replace(‘data:image/png;base64,’, ”);

type: ‘POST’,
url: “fileupload.aspx/UploadCanvasImage”,
data: ‘{ “imageData” : “‘ + dataURL + ‘” }’,
contentType: ‘application/json; charset=utf-8’,
dataType: ‘json’,
success: function (msg) {


and your .ASPX or MVC is like this:

public static string UploadCanvasImage(string canvasImgData)
string Pic_Path = HttpContext.Current.Server.MapPath(“MyPicture.png”);
using (FileStream fs = new FileStream(Pic_Path, FileMode.Create))
using (BinaryWriter bw = new BinaryWriter(fs))
byte[] data = Convert.FromBase64String(canvasImgData);
return “success”;


You, find out that the the WebMethod method is not being called.

Reason: It seems the canvas image is large.

You need to add this to the web.config to make this work:

<jsonSerialization maxJsonLength=”10000000″ />


Now, the JQUERY AJAX will be able to call the method successfully.

Prevent scrolling and zooming on touch within the browsers in mobile devices

Published by:

If you want that a user should not be able to scroll or zoom via touch in the web browser of a mobile device, use this code in the HTML:

<!–Prevents iPhone, iPad, and touch devices from scrolling or zooming when touched–>
<meta name=”viewport” content=”width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0″ />
Enjoy the tip!

Note: Most useful: when you are building and interactive HTML5 Canvas!

Mutex vs Semaphores – The toilet example

Published by:

I came across this post somewhere which is very easy for anyone to understand about Mutex and Semaphores.


Is a key to a toilet. One person can have the key – occupy the toilet – at the time. When finished, the person gives (frees) the key to the next person in the queue.

Officially: “Mutexes are typically used to serialise access to a section of re-entrant code that cannot be executed concurrently by more than one thread. A mutex object only allows one thread into a controlled section, forcing other threads which attempt to gain access to that section to wait until the first thread has exited from that section.”
Ref: Symbian Developer Library

(A mutex is really a semaphore with value 1.)


Is the number of free identical toilet keys. Example, say we have four toilets with identical locks and keys. The semaphore count – the count of keys – is set to 4 at beginning (all four toilets are free), then the count value is decremented as people are coming in. If all toilets are full, ie. there are no free keys left, the semaphore count is 0. Now, when eq. one person leaves the toilet, semaphore is increased to 1 (one free key), and given to the next person in the queue.

Officially: “A semaphore restricts the number of simultaneous users of a shared resource up to a maximum number. Threads can request access to the resource (decrementing the semaphore), and can signal that they have finished using the resource (incrementing the semaphore).”
Ref: Symbian Developer Library

Windows 8.1, Windows 10 Emulators crashing in Visual Studio 2015

Published by:



a) I start Visual Studio and create/open Windows Universal Apps. Then I choose the appropriate Windows 8.1/Windows 10 emulator and start the debug.

b) The Emulator loads and shows “OS is starting” and keeps stuck there for long time. Then finally loads a popup giving this error:
“windows phone emulator is unable to connect to the windows phone operating system couldn’t set up the UDP port”

Seems pretty bad, right? Cursing the operating system guys? hmmmm.

Solution (will work no matter what):

a) Do not think about reinstalling stuff or repairing Visual Studio 2015/previous versions or reinstalling Hyper V, etc.

Try this OPTION I  first:

1.) Open Hyper-V

2.) Shutdown any existing configured Windows Phone emulators.

3.) Delete the existing Phone emulators you see in the list

3.) Click on “Virtual Switch Manager”

4.) Click on the “Windows Phone Emulator Internal Switch”

5.) Delete the existing “Windows Phone Emulator Internal Switch” by clicking “Remove”

6.) Click “Apply” and “OK”

This should work.

If this does not, then do this:


1.) All steps in OPTION 1

2.) Now, open “Network Connections”

3.) You will see there “vEthernet (Internal Ethernet Port Windows Phone Emulator Internal Switch)”

4.) But hey, you deleted this same switch in OPTION 1, but still it shows in the Network Connections page.

This is the problem.

5.) Now open Device Manager

6.)  Expand “Network Adapters”

7.) You will see the names appearing under Network Adapter match the same as “Device Name” mentioned in “Network Connections” window (option II.2)

8.) Find out the correct “Hyper-V Virtual Ethernet Adapter” to be removed.
(Please note that on your computer the name could be “Hyper-V Virtual Ethernet Adapter #2” or “Hyper-V Virtual Ethernet Adapter #3” or anything that would match the “Device Name” of OPTION II.3)

9.) Now, in Device Manager, right click the correct Network Adapter and choose “Uninstall”.
This should disappear from the list.

10.) Open “Network Connections” and see that “vEthernet (Internal Ethernet Port Windows Phone Emulator Internal Switch)” will no longer be present there.

11.) Open Visual Studio, run the project in your desired emulator.

12.) This time everything will work fine and the Emulator will boot up Windows 10 or Windows 8.


Angel Kaushish
(Microsoft Certified Solutions Developer)