Second Life of a Hungarian SharePoint Geek

July 15, 2012

Automatically setting the next statement to a specific position when debugging in Visual Studio

Filed under: Debugging, Macros, Tips & Tricks, Visual Studio — Tags: , , , — Peter Holpar @ 21:58

Have you ever faced to the problem during debugging in Visual Studio, that you find a problem in a code block, and would like to avoid this code without altering the code and rebuilding / restarting  the application? In this case you need to set the next statement to a specific line of code using the context menu (see below).

image

It is trivial when you need to do it just  a few time, but it can be rather tedious, if not impossible, if you are – for example – in a loop processing several hundreds of items, and should do it for each items.

Fortunately, it is easy to achieve this goal using Visual Studio macros. The following method – defined in a module called in this example DebugHelpers – jumps to the next bookmark, and sets the next statement to that position.

Sub GoToNextBookmark()
    DTE.ExecuteCommand("Edit.NextBookmark")
    DTE.ExecuteCommand("Debug.SetNextStatement")
End Sub

Having this method, all you need to do is to set a new breakpoint with When Hit… option at the line of code you want to jump from,

image

and set the GoToNextBookmark method in the Run a macro list:

image

Then mark the target of the jump with a bookmark, and you are ready.

Emulating slow server response times using Fiddler

Filed under: Fiddler, Testing — Tags: , — Peter Holpar @ 20:22

Recently I’m working on a Silverlight business application that communicates with the server side using RIA web services. On the customer’s test system we experienced an unpleasant behavior in the asynchronous operations due to the slow response time of some background systems. In our development system we were not able to reproduce these issues.

Fortunately, Fiddler can help to emulate the slow server response times as well as slow network speeds.

Setting slow network speed is easy using the UI. One should check the Simulate Modem speeds option in Rules / Performance.

image 

If you need to set custom speeds, you should modify the upload / download speeds (delay ms per KB) through the request-trickle-delay and response-trickle-delay session parameters (see these samples for details) in the CustomRules.js (Rules / Customize Rules…).

Our case was a bit complicated, as the amount of the network traffic was really not proportional with the response times. Small response packages was just as slow as huge ones. So I had to use a custom, fix delay in the OnBeforeResponse function.

I have achieved this delay using a custom wait function:

static function wait(msecs)
{
var start = new Date().getTime();
var cur = start;
while(cur – start < msecs)
{
   cur = new Date().getTime();
}
}

Then I can use this call in OnBeforeResponse:

wait(5000);

However, using this simple function call would make every response slow, not only the ones received from our test web server. For example, a web search, or checking your web mail on the same system would be slow as well – a quite inconvenient side effect.

The solution to the problem was an extra condition:

if (oSession.HostnameIs("localhost:64399"))
{
  wait(5000);
}

where localhost:64399 is the name and the port number of our test web system.

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 42 other followers