<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Nikhil Agarwal</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/nikhil_agarwal/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/nikhil_agarwal/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:50:28 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>ASP.NET issue with auto-generated designer page</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhil_agarwal/asp-net-issue-with-auto-generated-designer-page</link>
      <pubDate>Fri, 18 Apr 2014 16:30:11 GMT</pubDate>
      <dc:creator><![CDATA[Nikhil_Agarwal]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhil_agarwal/2014/04/18/asp-net-issue-with-auto-generated-designer-page/</guid>
      <description><![CDATA[I have been facing this issue with VS2013, whenever I change my .aspx file (.NET framework 4.5) with...]]></description>
      <content:encoded><![CDATA[<p>I have been facing this issue with VS2013, whenever I change my .aspx file (.NET framework 4.5) with updatePanel/Scriptmanager, designer file generate for that control is:</p>
<p>/// &lt;summary&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// ScriptManager1 control.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;remarks&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Auto-generated field.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// To modify move field declaration from designer file to code-behind file.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/remarks&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected global::System.Web.UI.WebControls.ScriptManager ScriptManager1;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;summary&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// UpdatePanel1 control.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;remarks&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Auto-generated field.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// To modify move field declaration from designer file to code-behind file.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/remarks&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected global::System.Web.UI.WebControls.UpdatePanel UpdatePanel1;</p>
<p>But I have to change it to :</p>
<p>/// &lt;summary&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// ScriptManager1 control.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;remarks&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Auto-generated field.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// To modify move field declaration from designer file to code-behind file.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/remarks&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected global::System.Web.UI.ScriptManager ScriptManager1;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;summary&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// UpdatePanel1 control.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;remarks&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Auto-generated field.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// To modify move field declaration from designer file to code-behind file.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/remarks&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected global::System.Web.UI.UpdatePanel UpdatePanel1;</p>
<p>&nbsp;</p>
<p>Fix:</p>
<p>1) Either reset the System.Web.UI.WebControls.WebParts.UpdatePanel back to System.Web.UI.UpdatePanel (same for ScriptManager) every time the ascx file is modified...[recommended] but tedious</p>
<p>2) I found that using a Register command at the top of the ASCX file seemed to properly override the default behavior of the designer to pick the 4.0 location for the 3.5 control (I think that is the underlying issue, it is a 4.0 designer backwards compatible with 3.5). [Recommended] but be careful while adding controls with &lt;asp:&nbsp;</p>
<p>&nbsp;</p>
<p><span>&lt;%<span><span><span>@</span></span></span><span><span>&nbsp;</span></span><span><span><span>Register</span></span></span><span><span>&nbsp;</span></span><span><span><span>TagPrefix</span></span></span><span><span><span>="asp"</span></span></span><span><span>&nbsp;</span></span><span><span><span>Namespace</span></span></span><span><span><span>="System.Web.UI"</span></span></span><span><span>&nbsp;</span></span><span><span><span>Assembly</span></span></span><span><span><span>="System.Web"</span></span></span></span>%&gt;</p>
<p><span>...</span></p>
<p>&nbsp;&lt;asp:ScriptManager&nbsp;runat="server"&nbsp;ID="smLocationsMap"&nbsp;/&gt;</p>
<p>3) <span>You can include system.web.dll, and system.web.design. dll in your bin folder (Security/ Other issues) [Not recommended]</span></p>
<p>&nbsp;</p>
<p><span>I hope this is helpful :)</span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Timeout a function call in C#</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhil_agarwal/timeout-a-function-call-in-c</link>
      <pubDate>Fri, 28 Mar 2014 13:52:00 GMT</pubDate>
      <dc:creator><![CDATA[Nikhil_Agarwal]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhil_agarwal/2014/03/28/timeout-a-function-call-in-c/</guid>
      <description><![CDATA[There are some scenarios when you can't afford to allow any long running external/internal method to...]]></description>
      <content:encoded><![CDATA[<p>There are some scenarios when you can't afford to allow any long running external/internal method to take forever and eat up your processing resource. You should time it out if it takes longer than X units.</p>
<p>&nbsp;There are several ways to do that. I like the way using cancellation token the most.</p>
<p>&nbsp;Here we are calling GetResult() method which might take longer than 5000ms.Code snippet:</p>
<pre class="scroll"><code class="csharp"> int QueryTimeOut = 5000; //in ms<br /> var tokenSource = new CancellationTokenSource();<br /> CancellationToken token = tokenSource.Token;<br /> var task = Task.Factory.StartNew(() =&gt; queryRun.GetResult(), token);<br /> timedOut = false;<br /> <br /> if (!task.Wait(QueryTimeOut, token))<br /> {<br /> timedOut = true;<br /> message = String.Format(" Method Timed out");<br /> tokenSource.Cancel();<br /> return -1;<br /> }<br /> Int32 result = Convert.ToInt32(task.Result);<br /> task.Dispose();<br /> return result;<br /> </code></pre>
<p><br />NOTE: Above code does not kill the GetResult() which still runs in background. To Abort processing of GetResult/ long running method, please see below snippet:</p>
<pre class="scroll"><code class="csharp"> using System;<br /> using System.Threading;<br /> using System.Collections.Generic;<br /> using System.IO;<br /> using System.Threading.Tasks;<br /> <br /> namespace n<br /> {<br /> public class MonitorSample<br /> {<br /> <br /> private static int GetResult()<br /> {<br /> int result = 0;<br /> while (++result &lt; 500)<br /> {<br /> Console.WriteLine(result);<br /> Thread.Sleep(5);<br /> }<br /> return result;<br /> }<br /> public static void Main(String[] args)<br /> {<br /> int QueryTimeOut = 50; //in ms<br /> int result = 0;<br /> Boolean timeOut = false;<br /> ManualResetEvent wait = new ManualResetEvent(false);<br /> Thread work = new Thread(new ThreadStart(() =&gt;<br /> {<br /> //some long running method requiring synchronization<br /> result = GetResult();<br /> wait.Set();<br /> }));<br /> work.Start();<br /> Boolean signal = wait.WaitOne(QueryTimeOut);<br /> if (!signal) {<br /> work.Abort();<br /> timeOut = true; <br /> }<br /> Console.WriteLine(String.Format("Result = {0}, timedout = {1}", result, timeOut));<br /> Console.ReadKey();<br /> }<br /> }<br /> }<br /> </code></pre>]]></content:encoded>
    </item>
    <item>
      <title>Designing /Programming Windows Workflow Foundation 4.0</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhil_agarwal/designing-programming-windows-workflow-foundation-4-0</link>
      <pubDate>Fri, 28 Mar 2014 13:45:00 GMT</pubDate>
      <dc:creator><![CDATA[Nikhil_Agarwal]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhil_agarwal/2014/03/28/designing-programming-windows-workflow-foundation-4-0/</guid>
      <description><![CDATA[&nbsp;
Think of any online task you do in your day to day life, it should have a workflow backing...]]></description>
      <content:encoded><![CDATA[<h3 class="post-title entry-title">&nbsp;</h3>
<p>Think of any online task you do in your day to day life, it should have a workflow backing up. e.g. you buy movie tickets online (Its a client side workflow, you go to ticketing site -&gt; chose tickets -&gt; confirm -&gt; pay). &nbsp;Other workflow is server-side workflow which is a background task. E.g. when you buy a product on Amazon. Steps, Chose a product -&gt; pay -&gt; A server side workflow should kick off which contacts actual seller, calculates estimated delivery time, add order details in your account, send confirmation email to buyer and other individual tasks.<br /> <br /> Today I want to write about Windows workflow foundation 4.0 (WF). There are other workflow frameworks like Oracle offers, Sharepoint workflow etc.<br /> <br /> But I personally liked this workflow framework. WF a framework used to perform work intensive sequence of tasks (known as activities). Always remember, workflows are used to "Just Do Work".<br /> E.g. do X -&gt; Check Y-&gt; See P -&gt; Send A and for 1 million users. Your workflow in workflow designer might look like: <br /> <img src="https://i.msdn.microsoft.com/dynimg/IC360007.jpg" alt="" width="320" height="240" /><br /> I have been working on WF since couple of months and I am amazed with the power of this framework. With this you can:-<br /> 1. Run independent tasks/Activities in parallel<br /> 2. If you have created a share point farm your workflow can run on multiple machines in parallel.<br /> 3. It can be triggered by a workflow or a timer job<br /> 4. Create custom activities to implement business logic.<br /> 5. Set up concurrency of workflows<br /> 6. Call external methods and use those results in workflow<br /> 7. Automate a sequential set of tasks.<br /> <br /> I would like to talk about performance of Windows workflow. Since it runs on the application server. Doing things wrong/inefficient can slow down the entire server and eat up the processor and clog the database.<br /> <br /> I want to talk about few things which you should keep in mind while programming or designing Windows workflow:<br /> 1.&nbsp;<strong>Performance</strong>: It&rsquo;s an important aspect of every piece of code. But it becomes very important in case of workflows. E.g. you have to give discount to user on your product based on the sales, page hits and other parameters in 1 million products on your website. Calculating discount for individual product should be very efficient, it should take less than a second by your workflow. Workflows should not run more than couple of hour. &nbsp;Keep batching in mind. If you are reading an item from database, processing it and writing into database try batching stuffs. Divide 1 million item in batches, read a batch of 10000 items -&gt; process them -&gt; save 10000 items together. Batch size is critical can be best explained by: <br /> <img src="https://www.stephen-smith.co.uk/blog/wp-content/uploads/2013/03/Economic-Batch-Size-Reinertsen.jpg" alt="" width="400" height="366" /></p>
<p>2.&nbsp;<strong>Logging</strong>: Log every failure, successes, high importance in proper category for telemetry and support purpose.<br /> 3.&nbsp;<strong>Scalability</strong>: What if you start dealing with 100 million products after supporting 1 million products. Keep this in mind. In that case, divide your products with category, run workflow for individual category. Don't do any unnecessary operation in your workflow. Which can slow down your workflow by many folds.<br /> 4.&nbsp;<strong>Modularization</strong>: Try to break your methods as small as you can. So that it can be used by some other activity, help you in unit testing and improves the maintenance of the code.<br /> 5.&nbsp;<strong>Memory</strong>: Keep memory leakages in mind. For egg. C# has a built in garbage collection, but always Dispose objects which are derived from Disposable interface. When your workflow is running keep track of memory used by the workflow process in the task manager. It should increase and become constant. If the memory should keep increasing during the life of the workflow, it&rsquo;s an alarming situation.<br /> 6.&nbsp;<strong>Activity flooding:</strong>&nbsp;Decomposition of every tasks to an activity might look fascinating. But creating every activity has a cost (creating activity and deleting activity) by the workflow. We should not create 3 activities for a million object. That means if the cost of Create + Delete of an activity is 0.01 sec then you can save 20K seconds = 5 hour by creating 1 activity to do all 3 things together.<br /> <br /> Remember workflows are made to "Do work&rdquo;. If you have some base cases, which will exit the workflow in between, check that condition before the workflow is kicked off.<br /> <br /> Let me know if you have more pointers to improve programming in WF.<br /> <strong>Disclaimer:</strong>&nbsp;Ideas/Views mentioned above are purely personal and learnt with Experience/reading. Feel free to correct me.&nbsp;</p>]]></content:encoded>
    </item>
  </channel>
</rss>