Saturday, December 8, 2007

Create Rich Web Apps with AJAX

Microsoft's ASP.NET AJAX Extensions provide a simple and productive way to AJAX-enable a Web site without writing a lot of JavaScript code. Adding AJAX functionality to a Web site allows users to experience a richer user interface that reduces or eliminates the need to reload the entire page every time users click on a button or select an item from a drop-down list. Adding AJAX functionality to a Web site also enables users to access the data they need more quickly and efficiently (see "Why Use AJAX?"). There's a simple way to add AJAX to your Web pages, and it's instructive to understand how that works, but that approach isn't robust enough for many real-world commercial development scenarios, such as the one this article discusses. The simplest way to add AJAX functionality to your site is to wrap page content in an UpdatePanel control's ContentTemplate. This approach requires only minimal effort (see Listing 1, for an example of using the UpdatePanel control and the Timer control). It's also an effective approach, but it sends ViewState back and forth between the client and server when asynchronous postback operations occur within the page. This can potentially lead to larger than expected request and response messages being exchanged. You can use tools such as Fiddler to view messages sent by UpdatePanel controls and monitor their content and size. For many developers, the UpdatePanel is all they need to AJAX-enable their Web applications. However, other developers might need to minimize request and response messages as much as possible, suggest values to users as they type data into a textbox, or load and format data directly in the browser rather than building it on the server. In these situations, Web services provide a good alternative that you can use in concert with UpdatePanel controls on a page. Using Web services, you can pull data from the client directly, which makes the initial page load faster in the browser. In this article, I'll show you how to create Web services and consume them using ASP.NET AJAX and explain how you can use Web services with the ASP.NET AJAX Toolkit. I'll also introduce you to the real-world e-Commerce Service to demonstrate how the ASP.NET AJAX Extensions can enhance your overall productivity and allow you to integrate external data into your Web site with ease. Web services have been supported in the .NET framework since its initial release in 2002. ASP.NET AJAX supports calling standard .NET Web services, but adds a slight wrinkle to the equation. Instead of sending standard Simple Object Access Protocol (SOAP) request and response messages, ASP.NET AJAX applications send JavaScript Object Notation (JSON) messages to services. JSON is a compact way to send data to and from a Web service and is supported in all major browsers (unlike XML and SOAP). Developers don't have to know JSON to utilize Web services because ASP.NET AJAX handles the serialization and de-serialization of message data into, and out of, JSON messages. Several ASP.NET AJAX Extensions classes are used behind the scenes to allow ASP.NET AJAX applications to talk to Web services. First, an HttpModule named ScriptModule ensures that messages are routed to service methods properly using a technique referred to as Representational State Transfer (REST). Second, an HttpHandler named ScriptHandlerFactory plays a key role in handling calls made to back-end services, as well as calls made to profile and authentication services. Finally, an attribute named ScriptServiceAttribute marks a Web service as being AJAX capable. All Web services consumed by ASP.NET AJAX applications must contain the ScriptServiceAttribute reference. Create a Web Service
Assume you want to create a Web service named MathService that exposes a Web Method named Add():
[WebService(Namespace = 
[WebServiceBinding(ConformsTo = 
public class MathService : WebService
   public int Add(int x, int y)
      return x + y;
You AJAX-enable the Web service's class by applying the ScriptSer­viceAttr­ibute class directly to it as shown. No other changes are required at the Web service level for AJAX-enabled applications to call it. Other classes such as ScriptMethodAttribute and Gener­ateTy­peAttribute can also be used in a Web service although they're not required. More information about these attributes can be found here. Web services called by ASP.NET AJAX-enabled pages must be in the same domain as the page where the call originates from. This is due to security restrictions built into the XmlHttpRequest object used to make Web service requests. Although you can't call external Web services directly using ASP.NET AJAX, you can still make calls to external Web services by creating a local Web service that acts as the middleman. For example, assume you want to create a Web service that calls an service to retrieve book information (see Listing 2). This Web service relies on a class named AmazonSearch to call the service through a Web service proxy object and retrieve the desired data. You can find the Web Service Description Language (WSDL) document that describes the Web service here, and you can sign up for a free access account here. provides a free Web service called Amazon e-Commerce Service that you can use to retrieve information about books, DVDs, albums, and many other items sold on the Web site. By using the service, you can display products on your Web site and even receive a portion of sale proceeds for items purchased from your site. The service can be accessed for free once you've registered (registration is also free) and received an access key. The e-Commerce Service supports the latest standards and the team supporting the service provides samples that demonstrate calling the service in multiple languages, as well as a forum for posting questions about the service. You might wonder why I chose to use a Web service from a commercial vendor, such as Amazon, because this goes against the grain of VSM's usual approach. The reason: I wanted to show you a real-world implementation in action, as opposed to an example more theoretical than practical, and few non-commercial examples exist that have the robustness of Amazon's approach. Plus, it's free, and the terms of use are reasonable. ASP.NET AJAX provides a simple and efficient mechanism for calling Web services that have been marked with the ScriptServiceAttribute class. You can't right-click on your Web site project in Visual Studio .NET 2005 and add a Web Reference to create a Web service proxy, but you can use ASP.NET AJAX's ScriptManager control to create a client-side proxy that handles calling the service and passing JSON messages. You accomplish this using the ScriptManager's Services property and the ServiceReference control:
<asp:ScriptManager ID="smp" runat="server">
         Path="AmazonService.asmx" />
         Path="Scripts/Amazon.js" />
Defining a service reference on the ScriptManager control causes a client-side proxy class to be generated and added to the page at runtime. This proxy code looks something like this:
<script src="AmazonService.asmx/js" 
Note that the ASMX file is called directly and that "js" is added to the end of the path. The service is marked with the ScriptService attribute, so the ASP.NET AJAX runtime generates the JavaScript proxy code needed to call the service automatically. To call a Web service using a client-side proxy object, you reference the service's namespace, class, and method name using JavaScript. Parameter data required by the Web service's Web Method is passed to the method along with the name of the callback method. All calls to Web services are made asynchronously, and the callback method is invoked when a Web service call returns data to the browser. When the page containing the client-side Web service proxy first loads, it calls the SearchBooks() method (see Listing 3). This method locates a div tag with an ID of divAmazon and assigns a value of "Loading Books" to its innerHTML property. It then calls the local AmazonService.asmx service by referencing the service's namespace (GolfClubShack), class (AmazonService), and Web Method name (GetBooks). The GetBooks() method accepts three parameters, including the book text to search, the data results page to grab, and the name of the callback method. In this example a callback named OnWSCallback() is defined. Data returned from the Web service is routed automatically to the OnWSCallback() method, which processes the data (see Figure 1). The method iterates through all of the books returned and accesses different properties of each book, such as ImageUrl, Title, and Price. Note that you access each property in a strongly typed manner, much as you would when writing server-side code using C# or VB.NET. This strongly typed access to object property data is made possible by the proxy code generated by the ScriptManager. In addition to shipping the ASP.NET AJAX Extensions, Microsoft has also released a separate download called the ASP.NET AJAX Toolkit (also available here). This toolkit contains more than 30 AJAX-enabled controls for performing a variety of tasks. One of the controls that ties in nicely to Web services is the AutoCompleteExtender control. You've probably seen such a control if you've visited the Google suggest site or have the Google search box embedded in your browser. You can use this control to provide suggestions to end users as they type into a textbox. The control works by reading characters typed into a textbox and passing them to a Web service. The Web service performs a lookup against a data source to find data items that match with the initial characters typed and passes the matching items back to the AutoCompleteExtender control. The control then shows the matching data items directly below the textbox so that users can select them (see Figure 2). Using the AutoCompleteExtender requires that you copy the AjaxControlToolkit.dll assembly into your Web site's bin directory. This assembly is available in the ASP.NET AJAX Toolkit. You need to reference the AjaxControlToolkit.dll assembly once the assembly is available to use. Do this in web.config or in the page where you want to use the AutoCompleteExtender control. Add this code to the web.config file's <system.web> begin and end tags to reference the assembly in web.config and make it available for all pages on a Web site:
      <add tagPrefix="toolkit" 
         assembly="AjaxControlToolkit" />
Add this code to the top of a page to reference the assembly in a specific page:
<%@ Register
After you reference the assembly, you can define the AutoCompleteEx­tender in the target page. The control boasts several key properties, including the target control ID to extend the textbox with auto-complete behavior, the minimum number of characters to accept in the target control before calling the Web service, and the name of the Web service and Web Method that will be called to look up data items. This code defines an AutoCompleteEx­tender control that extends a TextBox with an ID of txtSearch:
<toolkit:AutoCompleteExtender id="ac" runat="server"
Once the number of characters to watch for has been reached (as defined using the AutoCompleteExtender's MinimumPrefixLength property), the Web service defined on the control is called to look for matching data items. For example, this Web service handles searching for matching data items and returning them to the AutoCompleteExtender control to display on the page (see Listing 4). The GetSearchItems() Web Method accepts two parameters: prefixText and count. The prefixText parameter contains the characters typed by the end user, while the count parameter contains the number of matching items to return back to the AutoCompleteExtender control. Data items that start with the value supplied by the prefixText parameter are returned from the Web Method in a string array. The ASP.NET AJAX Extensions provide several different ways to retrieve data from a back-end server using AJAX technologies. Although the UpdatePanel control will be all that's needed in many situations, integrating Web services into your Web applications can result in smaller request and response messages, which can lead to faster load times. By leveraging Web services you can also process and format data directly on the client rather than on the server. Web services can also be used to aid users as they type into textboxes by using controls such as the AutoCompleteExtender control found in the ASP.NET AJAX Toolkit.

ASP.NET - Storing Images to Database and Retrieving to GridView


ASP.NET C# - Enter Key

ASP.NET 2.0 makes this problems easier and introduce a concept of a "default button". New defaultbutton attribute can be used with <form> or <asp:panel> control. What button will be "clicked" depends of where acutally cursor is and what button is choosen as a default button for form or a panel.

Here is sample HTML code that contains one form and one panel control:

<form defaultbutton="button1" runat="server">
    <asp:textbox id="textbox1" runat="server"/>
    <asp:textbox id="textbox2" runat="server"/>
    <asp:button id="button1" text="Button1" runat="server"/>
    <asp:panel defaultbutton="button2" runat="server">
        <asp:textbox id="textbox3" runat="server"/>
        <asp:button id="button2" runat="server"/>

Saturday, December 1, 2007

Linux: Israel Forums

Tapuz Forum Linux-Israel

Linux: Tips for new Ubuntu installation

35 Cool Applications to install on Ubuntu Google Desktop on Ubuntu 13 Must Do things on new Ubuntu installation A Casual guide to some commonly used Linux Commands Essential house keeping in Ubuntu

Installing libdvdcss2 and w32 video codecs in Ubuntu Gutsy Gibbon

Support for WMV, RealMedia and other formats has been bundled into the w32codecs package. This package is not available from the Ubuntu repositories due to licensing and legal restrictions.

For Ubuntu Gutsy Gibbon Users run the following command

sudo wget -O /etc/apt/sources.list.d/medibuntu.list

Now you need to copy the key using the following command

wget -q -O-¦ sudo apt-key add -

Update the source list using the following command

sudo apt-get update

Install Codecs using the following command

sudo apt-get install w32codecs libdvdcss2

Using above download locations you can install most of the mutimedia codecs for ubuntu.

sudo apt-get update

Mplayer Plugin for Firefox

If you want to install Mplayer with plug-in for Mozilla Firefox run the following command

sudo apt-get install mozilla-mplayer

Tuesday, November 20, 2007

Linux: Find files on your computer with find

A standard Linux system has an incredible amount of files installed. Looking for a file location can be a painful task to do though a file browser.

Fortunately, there is a nifty command line available by default on any Linux distribution: find.

find can virtually find anything on your computer and comes with a lot of options. This tutorial will introduce a basic use of it and show how you can search your filesystem for file names matching a name pattern.

On Debian based distros, find is part of the package findutils. find allow one to search for files on a filesystem based on different condition, creation date, modified date, file size, file type, permissions, name ....

In this tutorial, I will be focused on finding files/directories based on their name, in order to explain in more depth the syntax of find, I will also show how you can narrow down your search by adding condition on size and file modification time.

This will suit most searches, if you need more details, I would recommend looking at the find's manpage.

1. Find basis

The default syntax of find is as such:

find [path] [expression]

where path is the path used as root for searching pattern and expression the expression we want the file to match.

2. Finding a file based on filename

Let say for instance you want to find all .avi files in users home directories. Search files can be found with the following command:

# find /home -name '*.avi'

If you want to search for *.mpg and *.avi files, you will use the following:

find /home -name '*.mpg' -o -name '*.avi'

Case insensitive searches can be achieved by using the -iname switch:

find /home -iname '*.mpg' -o -iname '*.avi'

3. Adding some more criterias

Those kind of searches might returns far too many results, making it hard to find waht you were looking for in the first place.

Fortunately, you can narrow down the search by adding criteria such as the file size and the file modification date.

Let'search for .avi files bigger than 700M. This can be done with:

find /home/ -name '*.avi' -a -size +700M

Now, let's find the same subset of files that were modified less than 15 days ago:

find /home/ -name '*.avi' -a -size +700M -mtime -15

4. Adding some actions

Grand, we can now find files based on a subset of criteria. What would be even better is to apply some actions on those files. Action can be done with the use of -exec switch.
We can now find .avi file that are newer that 15 days, in this example, we are going to move those file to another location: /my/new/movies . I consider that this directory already exist on your system.
Moving .avi files bigger than 700M and younger than 15 days to /my/new/movies can be done with:

find /home/ -name '*.avi' -a -size +700M -mtime -15 -exec mv '{}' /my/new/movies/ \;

Mind the use of '{}' and \; (there is a space before \;).
'{}' matches the file that was found, while \; terminate the exec statement.

5. Conclusion

find is a powerful tool with an extensive set of statement. This article only covered a small subset of available features. For more information on the find command I recommend checking out its man page.

Powered by ScribeFire.

Saturday, November 10, 2007

Single Instance Application

Making an application single instance, can be achieved by using a mutex (Mutual Exclusion Semaphore). A Windows application loads the main form through the Application.Run( ) method. In the Main method, create a new mutex. If a new mutex is created the application is allowed to run. If the mutex has already been created, the application cannot start. This will ensure that only one instance will be running at any time.

// Used to check if we can create a new mutex
bool newMutexCreated = false;
// The name of the mutex is to be prefixed with Local\ to make
// sure that its is created in the per-session namespace,
// not in the global namespace.
string mutexName = "Local\\" +

Mutex mutex = null;
   // Create a new mutex object with a unique name
   mutex = new Mutex(false, mutexName, out newMutexCreated);
catch(Exception ex)
   MessageBox.Show (ex.Message+"\n\n"+ex.StackTrace+
        "\n\n"+"Application Exiting...","Exception thrown");
   Application.Exit ();

// When the mutex is created for the first time
// we run the program since it is the first instance.
   Application.Run(new AnimatedWindowForm());

When a new mutex is created the mutex name can be prefixed with either Global\ or Local\. Prefixing with Global\ means the mutex is effective in the global namespace.

Prefixing with Local\ means the mutex is effective in the user's session namespace only.

Windows XP and Windows 2003 allow fast user switching through Terminal Services Sessions. So if a mutex is created with a Global\ prefix, the application can have only one instance system wide. So if one user launches the application, other users cannot create a second instance in their sessions. If the mutex is not prefixed with Local\ it is effective per session only.

Placing Your C# Application in the System Tray

  1. To get started, open an existing C# Windows form (or create a new one).
  2. Open the Visual Studio Toolbox.
  3. Drag a NotifyIcon control onto the form. The control will named notifyIcon1 by default and placed below the form because it has no visual representation on the form itself.
  4. Set the NotifyIcon control's Text property to the name you want to appear when the user pauses the mouse over the application's icon. For example, this value could be "KillerApp 1.0".
  5. Set the control's Icon property to the icon that you want to appear in the System Tray
  6. Add an event handler for the form's Resize event that will hide the application when it's minimized. That way, it won't appear on the task bar.
  7. private void Form1_Resize(object sender, System.EventArgs e)
      if (FormWindowState.Minimized == WindowState)
  8. Add an event handler for the NotifyIcon.DoubleClick event and code it as follows so that the application will be restored when the icon is double-clicked.
  9. private void notifyIcon1_DoubleClick(object sender,
                                        System.EventArgs e)
       WindowState = FormWindowState.Normal;

At this point, your application will fuction perfectly in terms of an icon appearing in the System Tray when the application is run (see Figure 1), the application not appearing on the task bar when minimized and the application restoring itself when the Tray icon is double-clicked.

Figure 1

Now, let's see the steps involved with adding a context menu to the icon.

  1. From the Visual Studio Toolbox, drag a ContextMenu control onto the form.
  2. Right-click the ContextMenu control and select the Edit Menu.option.
  3. Type in the options that you want to appear in your context menu. For example, you can add options such as Restore and Close Application.
  4. As with any menu, double-click the menu item to create and code each item's handler. As an example, you could copy the code from the form's DoubleClick handler into the context menu's Restore handler and for the Close Application menu item; simply call the form's Close method.
  5. Finally, set the NotifyIcon control's ContextMenu property to the new context menu you just created by selecting the menu from the drop-down list. Figure 2 shows a simple Tray context menu.

Visual Studio Setup and Deployment

Video: Delayed Startup Setup Project CodeProjec Example

Friday, October 12, 2007

חידות לראיון עבודה

חידות בראיון עבודה הן משהו שקשה להתחמק ממנו אבל די קל לעבור אותן בעיקר כשערן רום מביא לכם את התשובות, אז קבלו את חלק א' של החידות והפתרונות העיוור והכדים
חידה - מול עיוור מונחים שני כדים, ברשותך 50 כדורים שחורים ו-50 כדורים אדומים.
עליך לחלק את הכדורים בצורה כזו שלעיוור יהיה הסיכוי הגבוה ביותר להוציא כדור אדום.
איך תעשה זאת?
פתרון - יש לשים כדור אדום אחד בכד מסוים ובכד השני את כל שאר הכדורים, כך נגיע לסיכוי של בערך 75%.
הסבר: בכד עם הכדור הבודד הסיכוי הוא מאה אחוז ובכד השני קצת פחות מחמישים אחוז.
שלוש קערות
חידה - יש לנו 3 קערות שבהן ישנן גולות שחורות, גולות לבנות או מעורב, גולות שחורות וגולות לבנות.
על כל קערה רשום פתק:
שחור, לבן או מעורב (שחור ולבן)
ידוע ששלושת הפתקים שקריים.
תוך כמה הוצאות של כדורים תדעו מה הפתק המתאים לכל קערה?
פתרון - הוצאה אחת תספיק.
הסבר: מאחר ונתון שכל הפתקים לא נמצאים על הקערה הנכונה די להוציא כדור אחד מהקערה המעורבת, בהתאם לצבע של הכדור שייצא נדביק מבדקה שחור או לבן ואת הפתקים האחרים פשוט נחליף. זה הסידור הנכון.
החבית הכבדה
חידה - יש 9 חביות ואחת כבדה יותר מהשאר. כיצד תאתרו את החבית הכבדה ביותר בעזרת שתי שקילות בלבד?
פתרון - שוקלים שתי קבוצות של 3 חביות, אם קבוצה אחת יותר כבדה אז שוקלים שם חבית אחת מול חבית אחת.
במצב של שיוויון בשקילה הראשונה ממשיכים עם שלושת החביות שלא שקלנו.
אם יש שיוויון בשקילה השנייה אזי החבית שנותרה בחוץ בשקילה זו היא החבית המבוקשת (הכבדה).
זמן ופתילים
חידה - אנו רוצים למדוד זמן בעזרת פתילים. לרשותנו שני פתילים אשר זמן הבעירה של כל אחד מהם הוא שעה. קצב הבעירה אינו קבוע (כלומר חצי מאורך הפתיל לא יבער חצי מזמן בערת הפתיל). כיצד תמדדו שלושת רבעי שעה?
פתרון - מדליקים פתיל אחד משני הצדדים ופתיל אחד רק מצד אחד, כשהפתיל הראשון מסיים מדליקים את הצד השני של הפתיל השני.
הסבר: אחרי שהדלקנו את הפתיל הראשון משני צדדיו תעבור חצי שעה. אז אם נדליק את הצד השני של הפתיל השני נקבל רבע שעה, סך הכל שלושת רבעי שעה.
כובעים בקופסה
חידה - בקופסה יש חמישה כובעים: שלושה שחורים ושניים לבנים. בוחרים שלושה באקראי ומעמידים בטור שלושה אנשים כאשר האחרון בטור רואה את הכובעים של אלה לפניו, אך לא את שלו. האמצעי רואה את של הראשון והראשון לא רואה אף כובע.
האחרון אומר:אני לא יודע איזה כובע יש לי.
האמצעי אומר:אני לא יודע איזה כובע יש לי.
הראשון אומר: אני יודע איזה כובע יש לי. איזה כובע יש לראשון?
פתרון - לראשון יש בהכרח כובע שחור.
הסבר: אם האחרון לא יודע איזה כובע יש לו מכאן שלשני הראשונים יש או שני כובעים שחורים או כובע שחור אחד וכובע לבן אחד.
מאחר וגם האמצעי לא יודע איזה כובע יש לו (ואם לראשון היה לבן הוא הרי היה יודע שיש לו שחור), נקבל שלראשון יש כובע שחור

Saturday, October 6, 2007

43 Exceptionally Useful AJAX Applications


What is ctfmon.exe And Why Is It Running?

You are no doubt reading this article because you are frustrated with the ctfmon.exe process that just won't stop opening no matter what you do. You remove it from the startup items and it just magically reappears. So what is it?

Ctfmon is the Microsoft process that controls Alternative User Input and the Office Language bar. It's how you can control the computer via speech or a pen tablet, or using the onscreen keyboard inputs for asian languages.

If you are using any of the above, you should leave it enabled. For everybody else, we'll get to the job of disabling this annoying service.


Depending on your system configuration, there are a number of different steps to disable it. I've tried to list all the methods below.

Step 1: Disabling in Microsoft Office 2003

We can remove the alternative text input from Microsoft Office 2003 by just removing that feature in the setup.

Note: I haven't figured out where the equivalent setting is for Office 2007 (if there is one), but we can also disable it a different way below.

Go to Add/Remove programs, choose to Change your installation of Microsoft Office and make sure you check the box for "Choose advanced customization of applications" before you hit next.


Find "Alternative User Input" in the list and change the dropdown to "Not available" so it looks like this:


Step 2a: Disabling in Windows XP

There's an additional step we can take to make sure it gets turned off in Windows XP, which really seems to be the best answer for XP users.

Open up Control Panel and choose Regional and Language Options.


Choose the Languages tab and then click on Details in the top section.


Now on the Advanced tab you can choose to "Turn off advanced text services", which should immediately close ctfmon.


You'll also want to take a look at the first Settings tab, and make sure that your "Installed Services" box looks similar to this one:


If you have more than one Installed service then ctfmon might come back… For instance on my system there was an input for my drawing tablet so I could use it as a text input… which I don't care about, so I clicked Remove on it.

Step 2b: Disabling in Windows Vista

The setting above for completely disabling text services doesn't seem to exist in Windows Vista as far as I can tell, but we can remove the additional input services using a similar method.

Open Control Panel, choose Regional and Language Options and then find "Change keyboards or other input methods".


On the Keyboards and Languages tab, you can select Change keyboards.


Now you'll finally be at the same screen as in Windows XP. You'll again want to remove the extra installed services in the list other than your default keyboard language.


Step 3: Remove From Startup

You won't want to perform this step before doing the others, because it will just be overwritten again. Open up msconfig.exe through the start menu run or search box, and then find the Startup tab.


Find ctfmon in the list and disable it by unchecking the box. Just remember that if you haven't disabled ctfmon through one of the other settings this won't help you a lot.

Step 4: If all else fails

You can just completely unregister the dlls that run the alternative input services by running these two commands from the run box (one at a time)

Regsvr32.exe /u msimtf.dll

Regsvr32.exe /u msctf.dll

If you perform this step, you should also use Step 3 to get rid of the startup entries.

Step 5: Reboot

Reboot your computer and then open a Microsoft Office application if you do have that installed. Verify that ctfmon.exe is not running.

For more information you can read the Microsoft article on the subject.


Saturday, September 29, 2007

Default Form Button

Form properties ->Misc->AcceptButton

Firefox - new profile

Step 1: Start Firefox and export your bookmarks as a file on your hard-drive (we'll need them later).

fast firefox browser

Step 2: Type firefox.exe - P in the Run box of Windows. (see screenshot)

Step 3: Click the Create Profile button without making any modifications to your existing profile (which is normally called "default")

Firefox Very Slow

Now when you Start Firefox in the new profile, you are very likely to be impressed with the speed. You can import the bookmarks that you saved in Step 1. If you have made any changes to the Firefox Dictionary, copy the persdict.dat word list file from the old profile folder to the new one.

Yes, there won't be any old Firefox add-ons in the new profile but the browser will be extremely quick and won't hog the CPU - just the way you want Firefox to run on your computer.

And if you ever need to revert to the old profile, just type Firefox -P again and click the old profile. Nothing is lost.



Tuesday, September 25, 2007

Impersonation - C#

SetACL - windows permissions management (GPL)

DOS command to delete directory with all sub directories without confirmations

Windows XP DOS command deletes the C:\TEST directory and all subdirectories WITHOUT ANY WARNING:


/S = Removes all directories and files in the specified directory in addition to the directory itself. Used to remove a directory tree.
/Q = Quiet mode, do not ask if OK to remove a directory tree with /S.

Friday, September 7, 2007

Clean Up Ubuntu Grub Boot Menu After Upgrades

To remove GRUB entries, we'll need to edit the file /boot/grub/menu.lst. You can do this by using Alt+F2 and then typing in the following command:

gksu gedit /boot/grub/menu.lst


Now that we've got the file open, scroll down to the bottom of the file where it says "End Default Options", and you'll find all the menu entries for the various kernels in here. You can just select and delete the ones you want.


Save the file, and then the next time you boot up you'll see a much nicer set of options.


No need to delete those lines to simplify the GRUB menu. The easier way to keep only newest lines is to open the menu.lst (gksu gedit /boot/grub/menu.lst), find "#howmany=all" and change it to "#howmany=1″. Then run "sudo update-grub" to update changes. Next time, only newest kernel lines will be shown.


Tracking Down Svchost Process

In CMD window write:

tasklist /svc

Monday, September 3, 2007

Directory Security and Access Rules


using System.Security.AccessControl;
    FileSystemAccessRule faRule;
    FileSystemRights fsrRights;
    fsrRights = FileSystemRights.FullControl;
    faRule = new FileSystemAccessRule(
        new NTAccount("DOMAIN\\user"), 
        InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, 
        PropagationFlags.InheritOnly, AccessControlType.Allow
    //File.SetAccessControl(txtFile.Text, security);
    DirectorySecurity dirsec = Directory.GetAccessControl(@"\\server\sub$\folder");
    Directory.SetAccessControl(@"\\server\sub$\folder", dirsec);


The best explanation (MSDN)



ACL Propagation rules

Saturday, August 25, 2007

Ms Word tips

Where Was I? I get up and walk around frequently when I’m writing—gets the blood flowing. Sometimes I close a document I am editing, and when I come back to it and open it up, I just hit Shift + F5 to return to the exact place in the document where I was editing.

Serial Saves. If you’re like me, you often have many documents open at once. For safety’s sake, I like to frequently save all of them at once. To do this, hold down the Shift key when you go to the File menu. This changes Save to Save All.

Paragraph Hopping. You can circumvent the multi-step process of cutting, pasting and deleting to move paragraphs with an easy paragraph hopping feature. Often when I’m writing, I decide that a given paragraph would work better above or below another one. Do this: Go into a document with several paragraphs and put your cursor at the beginning of one of the middle paragraphs. Hold down the Shift and Alt keys in unison, then use the up and down arrow keys to “hop” the paragraph to new positions in the document.

One Fell Swoop Word Deletion. You can delete entire words with your keyboard. Just put your cursor at the beginning of the word and press Ctrl and Del together. This is very useful when editing.

Customize Line Spacing and Alignment. The Ctrl key is your best buddy when you want to experiment with line spacing and alignment variations. Ctrl + 1 provides single spacing, Ctrl + 2 provides double spacing and Ctrl + 5 provides 1-1/2 line spacing. Ctrl + R right aligns a paragraph, Ctrl + L left aligns one, and Ctrl + E centers one.

Quick Selecting. You can select all text between the current location of your cursor and the end of the current paragraph by hitting Ctrl + Shift and the down arrow.


Ctrl + [ or ], de- or increases the font of the selected text with 1 point.


Ctrl + “+” for subscript and ctrl + shift + “+” for superscript


Shift + F3 changes the case of selected text — UPPER — lower — Sentence case.


After ctrl-Z you can step back your changes by using Ctrl Y.


Press Control + Shift + C to copy the formatting and styles.


Select the location of the text where the formatting and style needs to be applied, and then
Press Control + Shift + V to paste the style and formatting (including Colors, Fonts, Font sizes, Paragraph styles, Headings and everything else).

Microsoft Keyboard Shortcuts


Friday, August 24, 2007

DataGridView - Copy multiple cells to clipboard

How to: Enable Users to Copy Multiple Cells to the Clipboard from the Windows Forms DataGridView Control

DataGridView Column Header Style

In order to use styles in your DataGridView control for your .NET 2.0 Windows application, you must specify dgvMyDataGridView.EnableHeadersVisualStyles = false.
Example of the code:

//Instantiate new DataGridViewCellStyle
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 =
    new System.Windows.Forms.DataGridViewCellStyle();

//Define Header Style
dataGridViewCellStyle2.Alignment =
dataGridViewCellStyle2.BackColor = System.Drawing.Color.Navy;
dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif",
    8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle2.SelectionBackColor =
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.Color.Navy;
dataGridViewCellStyle2.WrapMode =

//Apply Header Style
this.dgvTransactions.ColumnHeadersDefaultCellStyle =

//Disable Headers Visual Styles - apparently there is an "automatic"
// visual style that needs to be disabled
this.dgvTransactions.EnableHeadersVisualStyles = false;

Cell Styles in the Windows Forms DataGridView Control


DataGridView - Conditional Color Change

If DataGridView.Rows(i).Cells("locuscount").Value = "0" Then
          DataGridView.Rows(i).Cells("Status").Style.BackColor() = Color.AliceBlue
End If

DataGridView - Click Location & Selected Col/Row


For selected column and row:

private void myDataGridView_MouseDown(object sender, MouseEventArgs e)
    int ColumnIndex =myDataGridView.SelectedColumns[0].Index;  // Selected Column Index
    int RowIndex = myDataGridView.SelectedRows[0].Index;  // Selected Row Index
For click location use:
DataGridView.HitTestInfo myHit = dataGridView1.HitTest(e.X, e.Y);
if (myHit.Type == DataGridViewHitTestType.Cell)
    // select row == myHit.RowIndex;

Friday, August 3, 2007

Remove Old Drivers After Upgrading to New Hardware

If you are experiencing weird issues after upgrading your hardware, or you've just upgraded to the latest hardware device and aren't seeing the performance you'd like, you might want to remove the old drivers which are still installed for the old hardware, even though you can't normally see them in device manager.

What you have to do is set a less-known flag to allow you to see non-present devices, and then launch device manager. You'll then see the old devices in the list, and can uninstall the drivers for them.

In Windows Vista, the first thing you'll need to do is open a command prompt in administrator mode. Type cmd into the start menu search box, and then use Ctrl+Shift+Enter to open in administrator mode. (You can also right-click on the command prompt and choose Run as Administrator)

Now paste in the following line:


Then type in devmgmt.msc to start up Device Manager from the administrator command prompt.

Once you are in Device Manager, go to the View menu and choose Show Hidden Devices, which will show all the device drivers including things that aren't currently installed in your computer.

You can right-click on the driver and then choose Uninstall from the menu to remove the drivers for that old hardware.

I've found that this can resolve a lot of weird issues, and even increase performance on some machines where you've upgraded a ton of times. This isn't necessarily going to increase performance, but it's nice to have a tidy computer nonetheless.

This tip also works the same in Windows XP.


Friday, July 13, 2007

Control Firefox Tabs With Your Keyboard

Firefox makes mouse-less browsing a breeze with these simple shortcuts:
  • Ctrl T will open a new tab
  • Ctrl shift T will undo closed tab
  • Ctrl Page Up and Ctrl Page Down will scroll through your tabs
  • Ctrl Number will bring you instantly to a certain tab.  eg. If you hit Ctrl and ?3? you will go to the third tab
  • Ctrl D will bookmark the current tab
  • Ctrl Shift D will bookmark all the tabs in the window

Thursday, July 12, 2007

Bash Tutorial


bashscripting.pngBash scripts are collections of command line operations that automate frequently-performed actions in the terminal. If you're sick of typing out a set of commands one by one, it's time to script 'em out. Tech site Computer Science Directory has a full introduction to bash scripting perfect for the absolute beginner and advanced enough for seasoned bash pros.



Tuesday, July 10, 2007

Hotwire graphical terminal

Hotwire.pngFree open-source app Hotwire is a GUI-based terminal with auto completion. Hotwire has most of the functionality of the bash shell tucked into an easy-to-use GUI. Intended to replace the Linux terminal, Hotwire is perfect for Linux beginners. Hotwire is a perfect way for new users to dip a toe into the terminal without diving in head first. Hotwire is a free download for Linux only. Ubuntu users can install Hotwire using:

sudo apt-get install hotwire

*Hotwire isn't in the Ubuntu repository. You have to download the .deb file from and install it manually.

This is also for Windows. See



Sunday, July 8, 2007

Wikipedia for video - Vidipedia

Vidipedia is the first wiki on the internet to feature unlimited,  streaming video as a media option. Users can edit any page or video they like, creating an organized archive of digital media.

Min Map Wikipedia - WikiMindMap

 WikiMindMap takes a pleasant visual approach to the text heavy Wikipedia, showcasing additional relevant content that you may have never searched for.

Saturday, June 30, 2007

Got Friends? 2500 שקל

החברה משלמת עד 2,500 ש”ח לכל מי ששולח קורות חיים (קו”ח) של מועמד שיתקבל לעבודה.

מה עודאפשר לעשות עם האתר הזה? 

* קורות חיים בכמיות ענקיות - אם אתם חושבים בגדול הינה לכם רעיון להקמת אתר. הרעיון בכלליות הוא לפתח רעיון מקורי לפתיחת אתר “מחפשי עבודה” ולעבוד עם האתר Got Friends. חוץ מהכסף מהפרסומות שתרוויחו מהאתר אם יהיה פופולרי, תוכלו להרוויח גם אלפי שקלים משליחת קו”ח וכבר עשו את זה (והתוצאות חיוביות - 4500 קו”ח).

* הפניה עצמית - אם אתם מחפשים עבודה בתחומיים הדרושים בחברה, אפשר לשלוח קו”ח שלך ובמקרה שהתקבלת לעבודה משלמים לך גם כסף מהאתר וגם כסף כי אתה עובד (אפשר לעשות את זה, בדקתי).

* פרסום - עד לפני שחיפשתי על כסף באינטרנט, לא שמעתי על האתר הזה ואני מאמין שלא הרבה מכירים אותו. אני מציא לפרסם את האתר ולגרום לאנשים להירשם תחתיכם וכך להרוויח מהם (האתר משלם על 4 “דורות”).

Got Friends?

Convert PNG to ICO and back, online

Unix Filesystem

Windows users who dive into *nix without first researching the operating system are in for quite a shock. The complete lack of a C:\ drive can send Windows switchers into a tailspin. Thankfully, IBM developerWorks does an excellent job of explaining the structure and organization of the *nix filesystem and the perks of the *nix naming conventions.

Many directories in the UNIX file system serve a special purpose, and certain directories are named per long-standing convention. In this installment of the "Speaking UNIX" series, discover where UNIX stores important files.


UNIX file system [IBM developerWorks]

Wednesday, June 27, 2007 Update Checker

The Update Checker will scan your computer for installed software, check the versions and then send this information to to see if there are any newer releases. These are then neatly displayed in your browser for you to download.

Saturday, June 23, 2007


CodecInstaller is a Windows program that detects the Audio and Video codecs installed on your system, analyzes files to understand which codecs they require and suggests you to install them.
Check out the features tour for usage examples and screenshots of the program.


Operating System: Windows 98 - ME - NT 4(service pack5) - 2000 - WindowsXP - Windows Vista
Libraries: Microsoft .NET Framework 2 or higher is required in order to use CodecInstaller. It is freely downloadable from site


DOWNLOAD & changelog:
CodecInstaller 2.5



List Of Generators For a Website

Gmail - One Click Conversations

Allows you to view recent conversations with someone in just one click. Also adds rollover popup menu (ala built in quick contacts) to icon in message view.

Wednesday, June 20, 2007

NirCmd v2.00 - Freeware command-line tool

Windows only: Freeware command-line app NirCmd extends the functionality of the Command Prompt. NirCmd is a small command-line utility that allows you to accomplish tasks using the Command Prompt that would normally require a user interface. NirCmd has no "formal" installation process. All you need to do is copy "NirCmd.exe" to "C:\Windows" and then begin using it with Command Prompt. You can grab a list of the uses of NirCmd at the project homepage. NirCmd is a small command-line utility that allows you to do some useful tasks without displaying any user interface. By running NirCmd with simple command-line options, you can write and delete values and keys in the Registry, write values into INI files, dial to your internet account or connect to a VPN network, restart Windows or shut down the computer, create shortcuts to a file, change the created/modified date of a file, change your display settings, turn off your monitor, open the door of your CD-ROM drive, and more... NirCmd is a small command-line utility that allows you to do some useful tasks without displaying any user interface. By running NirCmd with simple command-line option, you can write and delete values and keys in the Registry, write values into INI file, dial to your internet account or connect to a VPN network, restart windows or shut down the computer, create shortcut to a file, change the created/modified date of a file, change your display settings, turn off your monitor, open the door of your CD-ROM drive, and more... Examples of what you can do with NirCmd Open the door of J: CD-ROM drive nircmd.exe cdrom open j: Close the door of Y: CD-ROM drive nircmd.exe cdrom close y: Increase the system volume by 2000 units (out of 65535) nircmd.exe changesysvolume 2000 Decrease the system volume by 5000 units (out of 65535) nircmd.exe changesysvolume -5000 Set the volume to the highest value nircmd.exe setsysvolume 65535 Mute the system volume nircmd.exe mutesysvolume 1 Unmute the system volume nircmd.exe mutesysvolume 0 Switch the system volume between the mute and normal state. nircmd.exe mutesysvolume 2 Create a shortcut on your desktop that switch the system volume between the mute and normal state. nircmd.exe cmdshortcut "~$folder.desktop$" "Switch Volume" mutesysvolume 2 Turn off the monitor nircmd.exe monitor off Start the default screen saver nircmd.exe screensaver Put your computer in 'standby' mode nircmd.exe standby log off the current user nircmd.exe exitwin logoff Ask if you want to reboot, and if you answer 'Yes', reboot the computer. nircmd.exe qboxcom "Do you want to reboot ?" "question" exitwin reboot Turn off your computer nircmd.exe exitwin poweroff Turn off all computers specified in computers.txt ! multiremote copy "c:\temp\computers.txt" exitwin poweroff force Dial to "My Internet" connection nircmd.exe rasdial "My Internet" Disconnect the "My Internet" connection nircmd.exe rashangup "My Internet" Make your Internet Explorer windows 75% transparent ! (192 / 256) nircmd.exe win trans ititle "internet explorer" 192 Minimize all your Internet Explorer windows nircmd.exe win min class "IEFrame" Close all your Internet Explorer windows nircmd.exe win close class "IEFrame" Close all your Explorer windows (My Computer, folders, and so on) nircmd.exe win close class "CabinetWClass" Hide all your Internet Explorer windows nircmd.exe win hide class "IEFrame" Show all your Internet Explorer windows (after you made them hidden with previous example) nircmd.exe win show class "IEFrame" Center all top-level windows nircmd.exe win center alltop Remove the title bar of My Computer window. nircmd.exe win -style title "my computer" 0x00C00000 Return the title bar of My Computer window that we removed in the previous example. nircmd.exe win +style title "my computer" 0x00C00000 Set the My Computer window to right-to-left order (For hebrew and arabic languages) nircmd win +exstyle title "my computer" 0x00400000 Set all child windows of My Computer window to right-to-left order (For hebrew and arabic languages) nircmd win child title "my computer" +exstyle all 0x00400000 Create a shortcut on your desktop that closes all your Internet Explorer windows nircmd.exe cmdshortcut " "~$folder.desktop$ "Close All IE" win close class "IEFrame" Create a shortcut on your desktop that hides all your Internet Explorer windows nircmd.exe cmdshortcut " "~$folder.desktop$ "Hide All IE" win hide class "IEFrame" Create a shortcut on your desktop that shows back all your Internet Explorer windows nircmd.exe cmdshortcut " "~$folder.desktop$ "Show All IE" win show class "IEFrame" Set the Windows Calculator as top-most window (above all other windows) nircmd.exe win settopmost title "Calculator" 1 Set the Windows Calculator back to regular window (non top-most window) nircmd.exe win settopmost title "Calculator" 0 Create a shortcut to Windows calculator under Start Menu->Programs->Calculators nircmd.exe shortcut "f:\winnt\system32\calc.exe" "~$folder.programs$\Calculators" "Windows Calculator" Hide the desktop window nircmd.exe win hide class progman Show the desktop window (After hiding it in previous example) nircmd.exe win show class progman Hide the start button on the system tray nircmd.exe win child class "Shell_TrayWnd" hide class "button" Show the start button on the system tray nircmd.exe win child class "Shell_TrayWnd" show class "button" Hide the clock on the system tray nircmd.exe win child class "Shell_TrayWnd" hide class "TrayClockWClass" Show the clock on the system tray nircmd.exe win child class "Shell_TrayWnd" show class "TrayClockWClass" Kill (terminate) all instance of Internet Explorer processes nircmd.exe killprocess iexplore.exe Create a shortcut on your desktop that opens the door of K: CDROM drive when you run it. nircmd.exe cmdshortcut "~$folder.desktop$" "Open CDROM" cdrom open k: Create a shortcut to NirSoft Web site on your desktop nircmd.exe urlshortcut "" "~$folder.desktop$" "NirSoft" Add NirSoft Web site to your Favorities under Links folder. nircmd.exe urlshortcut "" "~$folder.favorites$\Links" "NirSoft" Create a shortcut to NirSoft Web site on the desktop of all computers listed in computers.txt nircmd.exe multiremote copy "c:\temp\computers.txt" urlshortcut "" "~$folder.common_desktop$" "NirSoft" Set the display mode to 800x600x24bit colors nircmd.exe setdisplay 800 600 24 Create a shortcut on the desktop that set the display mode to 800x600x24bit colors nircmd.exe cmdshortcut "~$folder.desktop$" "800x600x24" setdisplay 800 600 24 Copy all shortcuts on your desktop to another folder (f:\temp\desktop). nircmd.exe execmd copy "~$folder.desktop$\*.lnk" f:\temp\desktop Restart your Apache server (under Windows NT/2000/XP/2003) nircmd.exe service restart apache Create a shortcut on your desktop that restarts the Apache server nircmd.exe cmdshortcut "~$folder.desktop$" "Restart Apache" service restart apache Restart your IIS nircmd.exe service restart w3svc Restart MySql nircmd.exe service restart MySql Open the desired Registry key/value in RegEdit nircmd.exe regedit "HKLM\Software\Microsoft\Windows\CurrentVersion" "CommonFilesDir" Open the Registry key that you copied to the clipboard in RegEdit. nircmd regedit "~$clipboard$" Disable the screen saver nircmd.exe regsetval sz "HKCU\control panel\desktop" "ScreenSaveActive" 0 Enable the screen saver nircmd.exe regsetval sz "HKCU\control panel\desktop" "ScreenSaveActive" 1 Change the date/time of the specified filename (creation time and modified time) nircmd.exe setfiletime "c:\temp\myfile.txt" "24-06-2003 17:57:11" "22-11-2005 10:21:56" Copy your desktop folder path to the clipboard nircmd.exe clipboard set ~$folder.desktop$ Copy your start menu folder path to the clipboard nircmd.exe clipboard set ~$folder.start_menu$ Copy the content of info1.txt (simple text file) to the clipboard nircmd.exe clipboard readfile "c:\My Files\info1.txt" Add the text content of clipboard to info1.txt nircmd.exe clipboard addfile "c:\My Files\info1.txt" Clear the clipboard nircmd.exe clipboard clear Create all folders specified in "c:\temp\folders.txt". The folder path names are separated by CRLF characters. nircmd.exe paramsfile "c:\temp\folders.txt" "" "" execmd md ~$fparam.1$ Install the specified .NET assembly in the global assembly cache (like gacutil) nircmd.exe gac install "C:\temp\MyAssembly\bin\MyAssembly.dll" Empty the recycle bin in all drives. nircmd.exe emptybin Answer 'Yes' to a standard Windows message-box. nircmd.exe dlg "" "" click yes

Saturday, June 9, 2007

Firefox - Paste multiple lines to input boxes

Type "about:config" in the location bar. In the "Filter" field type "singleline." You can set the value to 2 for editor.singleLine.pasteNewlines, which will allow pasting of multiple lines to input boxes.


Use external source viewer:

view_source.editor.external = True
view_source.editor.path to Notepad++



Saturday, June 2, 2007

SMPlayer - A VLC alternative?

SMPlayer is a video player that is supporting the most important video formats out of the box including avi, mpg, mov, wmv and vob plus numerous other formats.

It is also possible to play DVDs and Internet streams with the video player that is available for Windows and Linux. Several ways of displaying subtitles and various subtitle formats are supported including srt, sub and DVD subtitles.



Official Page

Tuesday, May 29, 2007

Close chip bags without the clip

Disable Caps Lock

Now you can disable your Caps Lock key in Windows... without any special software, and without having to pry the key off with a screwdriver. Read on to find out how. I also have a page on how to disable the Windows key.


Accidentally hitting the Caps Lock key when typing up an email or coding can be maddening. Most people never use it anyway, so why not disable it? In Windows, you can by adding some keyboard scancode mapping information to your Windows registry. The complete details are at To make it even easier, I decided to add some .REG files so you can disable your shift key yourself without needing to muck around with the registry.


This method of disabling the Caps Lock key works with all modern Windows variants: Windows 2000, Windows XP Pro & Home and Windows 2003. It will not work with older versions.


  • These files are provided without warranty. Use them at your own risk.
  • These files will overwrite any keyboard mappings you currently have.
  • .REG files update your Windows registry. Incorrect changes to the registry may damage Windows or other installed software. Be sure you know what a given .REG file contains before merging it into the registry.
  • These files are unsupported, please do not contact me with questions on their use.

Installation / Files

The following files are .reg files. They modify the Windows registry directly. You should download them to your PC and then double-click them to add them to your registry. After saying YES to the message box, reboot your machine and enjoy freedom from Caps Lock annoyances.

Note: You cannot combine this with my method for disabling the Windows key as it will replace those scancode mappings.

How to unlock a car + find a car

Blondie Unlocks Car - video powered by Metacafe
Boost Car Remote With Skull - video powered by Metacafe

Sunday, May 20, 2007

Disable Notification Balloons in XP

HKEY_CURRENT_USER\Software\Microsoft\Windows \CurrentVersion\Explorer\Advanced Source

Saturday, May 19, 2007

Shortcuts for Special Gmail Labels

In Gmail every built-in view (e.g.: inbox, trash, read mail) is actually a label. So if you want to view all the unread messages from the inbox, you could search for: label:inbox label:unread. You can combine these built-in labels with your labels and create interesting queries. But these queries can become long and hard to write. Fortunately, you can replace label with l and everything with still work fine. The previous query will become: l:inbox l:unread. If you still think the query is too long, Gmail has shortcuts for the special labels. ^b chats ^f sent mail ^i inbox ^k trash ^r draft ^s spam ^t starred messages ^u unread mail That means our query could become: l:^i l:^u. What about all the unread messages that aren't in the inbox? Search for: -l:^i l:^u. Source

Friday, May 11, 2007

mute the conversation with the Gmail keyboard shortcut "m"

The message is immediately removed from the Inbox view and all future messages (with similar subject line) will be archived automatically. You can search for muted messages using the search operator - is:muted And unless your email address is in the To: or CC: field, that email thread will never touch your Gmail inbox again. Muted unread mail, search using this query "label:^g is:unread"

Tuesday, May 8, 2007

At, you can put your own text into hundreds of fun image templates. - Create custom images thumbsup

Saturday, May 5, 2007

BackgroundWorker Component

MSDN Best Example example1 example2

The System.Threading Namespace

The System.Threading namespace provides classes and interfaces that enables multithreaded programming. This namespace includes a ThreadPool class that manages groups of threads, a Timer class that enables a delegate to be called after a specified amount of time, and a Mutex Class for synchronizing mutually-exclusive threads. System.Threading also provides classes for thread scheduling, wait notification, and deadlock resolution.

Some of the important classes in System.Threading namespace is discussed below.

Thread - Represents threads that execute within the runtime, to create and control threads.

ThreadPool - Posts work items to the thread pool. Queue work items for execution on the first available thread from the thread pool. One OS thread pool per process. Efficient use of thread resources.

Timeout - Contains timeout values for the system

Times - Specifies a delegate to be called at a specified time. The wait operation is performed by a thread in the thread pool.

Monitor - Provides the synchronization of threading objects using locks and wait/signals.

Mutex - A synchronization primitive that can also be used for interprocess synchronization. Wait can be used to request ownership of the mutex. The state of the mutex is signaled if no thread owns it.

The thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its executions. It must release the mutex as many times ti release ownership. If a thread terminates normally while owning a mutex, the state of the mutex is set to signaled and the next waiting thread gets ownership.

Life Cycle Methods

Starting a Thread

The thread class of System.Threading Namespace represents a thread object. By using class object, we can create new threads, delete, pause and resume threads. The thread class creates a new thread and Thread.Start method starts a thread.

thread = new Thread(new TreadStart( writeData )); thread.start();

where writeData is a function which will be executed by the program.

Killing a Thread

Thread class's Abort method is called to kill a thread permanently. Make sure IsAlive is called before Abort.





Pausing a Thread

Thread.Sleep method can be used to pause a thread for a fixed period of time.


Suspending a Thread

The Suspend method of the thread class suspends a thread. The thread is suspended until Resume method is called.

if( thread.ThreadState == ThreadState.Running) { thread.Suspend(); }

Resume a suspended Thread

The Resume method is called to resume a suspended thread. If the thread is not suspended, there will be no effect of Resume method.

if(thread.ThreadState == ThreadState.Suspended) { thread.Resume(); } Source