I found JavaScript setTimeout and setInterval functions quite handy for timer like functionality and some time wish I could use that in C# too. In an earlier post I create a C# like timer functionality in JavaScript. Now, I want to do opposite i.e. implement JavaScript setTimeout and setInterval like functionality in C#.

This is can be done very easily using Lamda expressions and Timer. Look at the below utility class -

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DailyCoding.EasyTimer
{
    public static class EasyTimer
    {
        public static IDisposable SetInterval(Action method, int delayInMilliseconds)
        {
            System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
            timer.Elapsed += (source, e) =>
            {
                method();
            };

            timer.Enabled = true;
            timer.Start();

            // Returns a stop handle which can be used for stopping
            // the timer, if required
            return timer as IDisposable;
        }

        public static IDisposable SetTimeout(Action method, int delayInMilliseconds)
        {
            System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
            timer.Elapsed += (source, e) =>
            {
                method();
            };

            timer.AutoReset = false;
            timer.Enabled = true;
            timer.Start();

            // Returns a stop handle which can be used for stopping
            // the timer, if required
            return timer as IDisposable;
        }
    }
}

I was searching a good jQuery plug-in for image zooming but couldn't find any which was matching my criteria. I need the lens effect while zooming images and it should work without much plumbing. So, I decided to create one and now sharing this with everyone.

What I need to use this?

  1. jQuery
  2. ImageLens plug-in – jquery.imagelens.js
  3. An image

How to use this?

Include jQuery and jquery.imageLens.js in you web page -

<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.imageLens.js" type="text/javascript"></script>

For default image lens just use imageLens as below. Note that it will automatically calculate actual size of image and start showing zooming -

Topbar message box plug-in can be used to showing message box or notifications on a web page. This is very simple to use and easy to configure. Of course you need jQuery to use this.

Usage

To use this plug-in include jQuery and juery.topbar.js in you web page -

<script src="jquery.js" type="text/javascript"></script>
<script src="juery.topbar.js" type="text/javascript"></script>

Now create a html element which you want to show in topbar as messagebox -

<p>
    <a href="javascript:void(0)" id="demo01">Demo 1 - Simple</a>
</p>
<div id="demo01-body" style="display:none;">
    This is a simple demo
    <span style="font-size: small">(click to close)</span>
</div>

When you create a web page you usually keep in mind how it will rendered on the browser and its usability. Sometime, depending upon the content, you also know that your page might be printed by end user. But you don’t want that the printer version of your page to be same as the screen version. Most of the time you might create a separate printable version of the page. User will click specially open the printable version and take its print or sometime he will directly print your webpage.

Now what are the issues here -

  1. The web page is not printer friendly therefore the content might get distorted while printing it into a A4 size paper.
  2. The print will contain unnecessary links and images while have no use in printable version.
  3. The webpage might have dark background which will lead to wastage of print ink.
  4. Some text might have light colors which may not be visible clear on a black & white printout.
  5. If you create separate printable view then it will involve another user action which sometimes user don’t do.

Visual Studio 2010 has finally released and is available for download. You can download various version from below location -

There lots of improvement in Visual Studio 2010 over past version. Below are some new great features of Visual Studio 2010 -

Better code intellisense

Visual Studio 2010 has better code intellisense support which make it easier for look for methods and functions. You can now easily search for inline keyword, or even use abbreviation to search for properties or methods.

There are lots of small tricks in .net which can be very useful if used wisely. In this post I want to discuss the use of DebuggerBrowsableAttribute. Using this attribute you can control how a member of class will be displayed in debugger windows during debugging. Before that consider small example:

public class Organization
{
    public List<Employee> Employees
    {
        get;
        set;
    }

    public Organization()
    {
        this.Employees = new List<Employee>();
    }
}

 

Like the Object oriented programming the exception handling is also not used while coding in JavaScript. That why in most of cases if there is any problem in one part in a page then surprisingly other part also stops working. In this post we will be discussing the various techniques to handle exceptions in JavaScript.

Using try..catch block

try..catch block in JavaScript is very much similar to the regular C# try..catch block. The suspected code will be put in try block and all exceptions which will occur in the try block will be caught in catch block.

window.onload = function()
{
    try
    {
        var x = 90;
        var value = x / y;
    }
    catch(err)
    {
        document.write(err.name + ": " + err.message + "<br/>");
    }
}
Output:
TypeError: 'y' is undefined

In this post I want to cover some very basic and small extension methods which are very useful for any developer. All below mentioned extension method are not doing any complex operation. Rather they are just performing very simple task which you generally encounter a lots of times in your day today coding.

1. IsNull

This is probably most commonly used expression. A lots of places in out code we check to null references. We usually add the obj == null or obj != null check to do this. Here is the IsNull extension method

public static bool IsNull(this object source)
{
    return source == null;
}

Using the you can avoid the lazy null check. Example:

public void ProcessData(DataSet input)
{
    if (!input.IsNull())
    {
        // business logic here
    }
}

This contest is closed now. There were very few comments; so it was not difficult to choose the winners. Here are the winners

1st Prize - 1000 Standard Size Business Cards - Alex Lyman
2nd Prize - 500 4x6" Postcards - Alin-T

Congrats winner. You will be soon contacted by UPrinting for the preferences.

Here is business card giveaway for the readers of DailyCoding. The prizes are sponsored by the UPrinting.

1st Prize - 1000 Standard Size Business Cards

2nd Prize - 500 4x6" Postcards

You can choose from any of their stocks for these items. The rules are very simple:

  1. Leave a comment (along with your email address) at the end of this post, describing what you would use the free business cards and/or postcards for.
  2. Two winners will be chosen based on most interesting comments.
  3. There is no fix end date of this contest.
  4. Winners in the United States and Canada qualify for free shipping. Shipping fees will apply to winners outside these areas.

Vista had come with new and cool look & feel. If you want to add the Vista Aero style theme to you WPF application running on Window XP then it is very easy trick. You don’t need any third party library or tool to achieve this.

To do this all you need to do is to add following lines of xaml code into the designer of your window right after window tag:

<ResourceDictionary Source="/PresentationFramework.Aero, 
   Version=3.0.0.0, Culture=neutral, 
   PublicKeyToken=31bf3856ad364e35, 
   ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml" />

If you want to apply this look through out the application then add this to app.xaml under <Application.Resources> section.

Recently Added

Database

More..
Step by Step Guide to Add a SQL Job in SQL Server 2005

by Ramesh Soni on Jul 10, 2008
Describes Step by Step process of adding a sql job in SQL Server 2005
51 Comment(s)

Generate New Guid (uniqueidentifier) in SQL Server

by Ramesh Soni on Jun 19, 2008
About how to generate a random unique identifier in using sql query in SQL server
27 Comment(s)

Add parameterized queries in MySql (OleDb)

by Ramesh Soni on May 18, 2008
Explains how to add parameters in odbc queries
5 Comment(s)

Design

More..
ImageLens – A jQuery plug-in for Lens Effect Image Zooming

by Ramesh Soni on Mar 28, 2011
Use this jQuery plug-in to add lens style zooming effect to an image
104 Comment(s)

jQuery Plug-in for Showing Message Box in Topbar

by Ramesh Soni on Mar 22, 2011
A jQuery Plug-in which you can use for showing notifications and messages in the topbar.
10 Comment(s)

Create Printer Friendly Web Page Using Media Attribute

by Ramesh Soni on Aug 4, 2010
How can we optimize a web page for printer without creating new page
2 Comment(s)

Add Vista Look to your WPF Control on Windows XP

by Ramesh Soni on Jan 27, 2009
Explains how to convert a XP looking UI into Vista look using WPF running under Window XP
7 Comment(s)

Customized Html Controls: Creating Custom Checkbox

by Ramesh Soni on Dec 17, 2008
Discuss about creating custom html checkbox under customized html controls.
18 Comment(s)

General

More..
EasyTimer - JavaScript style setTimeout and setInterval in C#

by Ramesh Soni on Oct 3, 2012
how to implement and use JavaScript style setTimeout and setInterval in C#
6 Comment(s)

Top 5 new features of Visual Studio 2010 and .NET 4

by Ramesh Soni on Apr 14, 2010
Discusses the new features of Visual Studio 2010 and .NET 4
11 Comment(s)

Using DebuggerBrowsable Attribute for a better view in debugger window

by Ramesh Soni on Jan 23, 2010
Describe how we can DebuggerBrowsable attribute for customizing the debugger window view.
8 Comment(s)

Top 5 Small but Must have Extension Methods

by Ramesh Soni on May 28, 2009
Covering a few very basic and use extension methods
9 Comment(s)

Random Sort a List Using LINQ

by Ramesh Soni on Nov 21, 2008
How to random Sort a List by using simple LINQ technique
9 Comment(s)

Others

More..
Business Cards and Postcards Giveaway : Comment and Win

by Ramesh Soni on Mar 26, 2009
Win free business cards and postcards. All you need to win is just comment
4 Comment(s)

MIME content-types with file extension

by Ramesh Soni on Jul 15, 2008
List of MIME content-types and their file extension
1 Comment(s)

Links - Jun 02, 2008

by Ramesh Soni on Jun 2, 2008
Some good links about web site design and development
0 Comment(s)

Scripting

More..
JavaScript Exception Handling Techniques

by Ramesh Soni on Aug 4, 2009
Various techniques of JavaScript exception handling are dicussed here
14 Comment(s)

Animated Progress Bar without Images

by Ramesh Soni on Sep 3, 2008
How to create a cool looking animated progress bar without using any images using javascript, css and html
10 Comment(s)

Object Oriented Programming with JavaScript : Timer Class

by Ramesh Soni on Aug 13, 2008
How to do object oriented programming with JavaScript by taking simple example to a timer class.
10 Comment(s)

Variadic Functions in JavaScript

by Ramesh Soni on Jun 26, 2008
Create and use function with indefinite number of parameters in javascript
2 Comment(s)

Using RegEx(Regular Expressions) in JavaScript

by Ramesh Soni on May 28, 2008
using javascript to create and verify user's input by using regular expression at client side
10 Comment(s)

Web

More..
How not to cache a page output in ASP.NET

by Ramesh Soni on Jul 31, 2008
Explains how not to cache pages in asp.net to avoid them stored at client side
17 Comment(s)

The Script tag runat="server" Problem Solution Using ResolveUrl

by Ramesh Soni on Jul 21, 2008
Solution to the script tag runat="server" problem
19 Comment(s)

How to force a file to download in ASP.NET

by Ramesh Soni on Jun 16, 2008
This article is about how we can force the user to dowload a particlar file or file type by adding the content-disposition header
11 Comment(s)

Implementing Cookieless Session (ASP.NET)

by Ramesh Soni on May 27, 2008
Explains how to implement cookieless authentication in asp.net by settings in web.config
11 Comment(s)

Create RSS feed programatically from data in C#

by Ramesh Soni on May 24, 2008
This article will explain how can you to create you own utility to generate rss feed from yous data programatically
21 Comment(s)

Windows

More..
Using Microsoft Agent in Windows .Net Application

by Ramesh Soni on Jun 4, 2008
How to use and animate MS in .NET Applications
4 Comment(s)

Using Invoke to access object in a windows forms/controls thread

by Ramesh Soni on May 26, 2008
How to use Invoke to handle cross thread calls to windows forms or controls
5 Comment(s)

How to crawl a web page/file in a .net application

by Ramesh Soni on May 23, 2008
Explains how we can crawl a web page or file using a virtual path and store the response locally
6 Comment(s)

How to get current assembly version

by Ramesh Soni on May 21, 2008
Extracting the version of currently executing assembly
2 Comment(s)

More..

Contact

For any help or queries contact me sa@dailycoding.com