Saturday, July 30, 2016

Database Management System

Introduction
A database is an organized collection of logical data. DBMS or Database Management System is the system software that stores and sustains the database. Database Management System is a window that allows users to interact with the database.

Major industries like Telecom, Hotel, Airlines, Textiles, Health, Education, Insurance uses some or the other DBMS software. There are wide varieties of DBMS software available in the market. Database systems like MS-SQL Server, DB2, SAP, CouchDB, PostgreSQL, SQLite, Sybase, RethinkDB, Berkeley, Redis, mongoDB, MySQL, Oracle, MS-Access are popular DBMS available in the market.

History
In the period of 1960s, Charles Bachman designed the first general purpose DBMS named as 'Integrated Data Source' which formed the basis of Network Data Model. He received ACM's Turing Award for his work in 1973.

In late 1960s, IBM developed Information Management System (IMS) DBMS for NASA's Apollo space program. This formed the basis of Hierarchical data model.

In 1970, Edgar Codd, at IBM, introduced Relational Data Model. The relational DBMS benefits and utilities were universally accepted by the industries and the corporate world for storing the data. Relational DBMS is more user-friendly and easy to use as compared to network and hierarchical data model.

Structured Query Language in DBMS
SQL is an ANSI and ISO standard language, developed to interact with the database. Earlier, SQL was popular as SEQUEL. SQL includes language elements like clauses, expressions, predicates, statements, and queries. SQL communicates with the database via DDL, DML, DCL, and TCL. The data structures and schemes are defined under DDL or Data Definition Language. DML or Data Manipulation Language includes insert, update, select and deletion of records. DCL or Data Control Language authorizes data access to users by Grant and Revoke statements. TCL or Transaction Control Language includes data transactions.

Elements Of DBMS
  1. Physical database
  2. Database engine
  3. Database scheme
  4. Schema objects
  5. Tables
  6. Fields
  7. Records
  8. Keys
  9. Relationships
  10. Data types
Advantages of DBMS
  1. Data security and consistency are very important when multiple users access the database simultaneously.
  2. Data retrieval is fast.
  3. Developing and maintaining DBMS is easier as compared to the file system.
  4. There is an inbuilt utility of backup and recovery when the system crashes.
Disadvantages of DBMS
  1. Complexity increases with increase in the size of data.
  2. Maintenance is expensive. 

Tuesday, September 22, 2015

MVC-Tutorial

Add 2 numbers in MVC
Download the sample project from the link below:
http://demos.essentialsolve.com/demos/Files/MVC/DemoCal.rar

- Create a new project in Visual Studio.

- Name the project as "MVCDemoCalc".

- Click Ok.
- In the next screen, select "Internet Application" in Project Template and Razor as View Engine. Click Ok.

- A new project opens. You will see 3 folders in the Solution Explorer named as View, Controller and Model as shown below.

- Create a New class named as MathCalc in the Model folder. Define a method named as Sum to add the 2 numbers.
public class MathCal
    {
        [DisplayName("Value1")]
        public double Value1 { get; set; }
        [DisplayName("Value2")]
        public double Value2 { get; set; }
        public double Sum(double v1, double v2)
        {
            return v1+v2;
        } 

    }

- Create a controller "MathCalController" in Controller folder.


- This class uses the MathCal class object. Below is the code:
  public class MathCalController : Controller
    {
        //
        // GET: /MathCal/         
        public ActionResult Index(MathCal objMathCal)
        {
            ViewBag.Results = objMathCal.Sum(objMathCal.Value1, objMathCal.Value2);
            return View(objMathCal);
        }

    }

- Compile the project to generate classes.
- Right click the ActionResult to generate the detail view.


- Give View Name as 'Index'. View Enginer as Razor. Select the checkbox 'Create a strongly typed view'. Selec the model class 'MathCal'. Choose Scaffold Template as Details. Click select. Below is the modified code of Index.cshtml:

@model MVCDemoCalc.Models.MathCal

@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    using (@Html.BeginForm())
    {
    <fieldset>
        <legend>MathCal</legend>

        <div class="display-label">
            @Html.DisplayNameFor(model => model.Value1)
            @Html.EditorFor(model => model.Value1)
        </div>

        <div class="display-label">
            @Html.DisplayNameFor(model => model.Value2)
            @Html.EditorFor(model => model.Value2)
        </div>

        <div class="display-label">
            @Html.Label("Result")
            @ViewBag.Results
        </div>
    </fieldset>
    <p>
        <input type="submit" value="Add" />
    </p>
    }
</body>

</html>

- Open RoutConfig.cs file located in App_Start folder. Change the default startup page as below:
public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "MathCal", action = "Index", id = UrlParameter.Optional }
            );

        }

- Run the program and check the output. Here below is the ouput:

Tuesday, June 23, 2015

Events in ASP.NET Program

Events

ASP.NET is an event-driven way of making web applications. With PHP and Classic ASP, you have one file, which is executed line after line, from start to end. However, ASP.NET is very different. Here we have events, which are either activated by the user in one way or another. In the previous example, we used the Page_Load method. Actually, this is an event, which the Page class calls when the page is loaded. We will use the same technique in the next example, where we will add a couple of controls to our simple hello world example. To make it a bit more interesting, we will change the "world" word with something defined by the user. Have a look at this codelisting, where we add two new controls: A Button control and a TextBox control.

<form id="form1" runat="server">
<div>
    <asp:Label runat="server" id="HelloWorldLabel"></asp:Label>
    <br /><br />
    <asp:TextBox runat="server" id="TextInput" /> 
    <asp:Button runat="server" id="GreetButton" text="Say Hello!" />
</div>
</form>
As you can see, we now have the 2 new controls added, but they really can't do much at the moment. You can run the example if you wish to check this out for your self - if you click the button, the page is simply reloaded. Let's change that, and let's start by doing it the easy way. VWD comes with a WYSIWYG editor, and while I hardly ever use it my self, it does make some things easier, like creating events. So, click the Design button in the bottom of VWD. Now you will see a visual representation of our page. We wish to add a Click event to the button, and this is very simply - just doubleclick the GreetButton, and you will be taken to the CodeBehind file of our page. As you can see, a fine new method has been added, called GreetButton_Click. If you have a look at the Default.aspx file (you need to go from Design view to Source view), you will see that an attribute has been added to our Button control, telling which method to call when the button is clicked. All this work done with a simple doubleclick. 

Now lets add some code to our new event. We wish to use the text from the TextBox, on our good old Label with the "Hello, world!" text. This is also very simple, and all it requires is a single line of code:


HelloWorldLabel.Text = "Hello, " + TextInput.Text;
Run the project again (F6), and you will see the our old page with a couple of new controls. The "Hello, world!" text is still there, because we set it in the Page_Load event. Now try entering a name in the textbox, and press the button. Voila, the text is changed, and we have just used our first control event. Notice how we can add code which is not necessarily called unless the user performs a specific task. This is different from the good old Classic ASP/PHP approach, but you will soon get used to it, and you will probably also come to like it a lot! 

Sunday, June 21, 2015

Twitter Bootstrap Pages




Twitter Bootstrap 20 Static Content Pages developed for a Greenfield project



I designed 20 static pages in MVC3 using HTML, Twitter Bootstrap CSS, JQuery. The gradient color combination and the entire flow looks like the site: 

1. http://www.microsoft.com/expression

2. http://demos.kendoui.com/web/datasource/remote-data.html







Add Article
I designed this page using twitter bootstrap css.





Add Note

When the 'Add Note' button is clicked a modal dialog appears where you can add data.



Add Profile
In this page I added 3 information widgets and a ListView with gradient background.




Add Service
In this page when 'Add Service' button is clicked, a modal dialog appears where you can add data. This data will be stored in SQL Server.



Add User
This page is designed to add details of the new users. The dropdown list and textboxes are designed to give a professional look.



Blog Details
This page is designed to display the details of the article. Here rich textbox is added where you can style your text. Also I added a Info widget on this page.





Blog Main
This page is designed blog summary in a table.





Contact Us





Manger Users
Twitter Bootstrap JQuery datatable added on this page with table paging, Add User and Search buttons.





Modal Generic Document Viewer 1
This page has a button which when clicked opens a modal dialog with image slideshow





Modal Generic Document Viewer 2
Image slide show in modal dialog. There are 4 buttons at the bottom for Downloading the image, Slideshow of all the images, display next image and previous image.




My Notifications
Here twitter bootstrap jquery datatable is used with pagination.




Partner Registration
This page displays textboxes, dropdown lists with Info widgets. I designed this page keeping in mind that the look and feel and the flow of the entire project should be same.





Profile Details
In this page the critical part was to create a list view similar to http://demos.kendoui.com/web/datasource/remote-data.html
Here the ListView should be with pagination instead of scrolling. I used JQuery for pagination of ListView.




Report
This page is designed with Info widgets and alerts using twitter bootstrap css.





Search
Simple search page with professional look and feel.




Search Result
In this page ListView with gradient background color is created. This ListView is with pagination and a search button.


Service Reports
This page contains an Info widget and a simple JQuery datatable with pagination




Update Service
For the page the requirement was that the textarea for 'Peer Note' should be re-sizable with fixed width and resize height. Usually when we expand a textarea the width and height both increase/decrease. I used CSS style to fix the width and resize the height of the textarea




Add Parcel
A simple page with professional look and feel and gradient color combination look like the site http://www.microsoft.com/expression/






Edit Profile
The color combination and the flow of  the page look like the site http://www.microsoft.com/expression/




























Monday, June 8, 2015

Sutra1

Sutra 1 - Ekadhikena Purvena

Meaning: By one more than the one before

Examples:

Square of numbers ending with 5 :

1) 255
= 2 X 3 | 52
= 6 | 25
Answer = 625

    Vedic Maths (Index)

    Vedic Maths Tutorials

    Brief History

    16 Sutras

    Sutra 2 - Nikhilam Navastascaramam Dasatah
    Sutra 3 - Urdhva-Tiryagbhyam
    Sutra 4 - Paravartya Yojayet
    Sutra 5 - Shunyam Samyasamuchchaye
    Sutra 6 - Aanyarupaye Sunyamanyat
    Sutra 7 - Sankalana-Vyavakalanabhyam
    Sutra 8 - Purna Puranabhyam
    Sutra 9 - Chalana-Kalanabhyam
    Sutra 10 - Yavadunam
    Sutra 11 - Vyasti Samastih
    Sutra 12 - Sesanyankena Caramena
    Sutra 13 - Sopantyadyamantyam
    Sutra 14 - Ekanyunena Purvena
    Sutra 15 - Gunitasamuchchaya
    Sutra 16 - Gunakasamuchchaye

    16 Sub-Sutras

    Sutra 1 - Anurupyena
    Sutra 2 - Sisyate Sesasmjnah
    Sutra 3 - Adyamadye Nantyamantyna
    Sutra 4 - Kevalaih Saptakam Gunyat
    Sutra 5 - Vestanam
    Sutra 6 - Yavadunam Tavadunam
    Sutra 7 - Yavadunam Tavadunikritya Vargancha Yojayet
    Sutra 8 - Antyayordashake 'pi'
    Sutra 9 - Antyayoreva
    Sutra 10 - Samuchchaya Gunitah
    Sutra 11 - Lopanasthapanabhayam
    Sutra 12 - Vilokanam
    Sutra 13 - Gunita Samuchchaya Samuchchaya Gunitah
    Sutra 14 - Dhvajanka
    Sutra 15 - Dwandwa Yoga
    Sutra 16 - Sudha

      Developer Links

      Sunday, June 7, 2015

      Creating First Website


      Introduction

      In VisualStudio, Open the File menu and select "New Web Site". You will be presented with the following dialog: 



      You need to select "ASP.NET Web Site", if it's not already selected. You should also name your new site. This is done by entering a name in the Location box. This text box is probably already filled for you, with the last part being something like "Website1". You can choose to accept this, as well as the location of the project, or you can enter a new one. I have created a folder, "My Websites", and within this folder, I would like to create the new project with the name of "WebSite1". For now, this is less important, but later on you might wish to gather all your projects in a specific folder. 

      This tutorial will focus on the C# language. Once again, no knowledge of this is required, so if you already know another .NET language, you will get to learn some C# with this tutorial as well. Select C# in the Language dropdown. Now, click the Ok button to create this new website. 

      VisualStudio2012 will create a very basic website for you, consisting only of a Default.aspx file (and it's partner, the Default.aspx.cs file) and an App_Data folder. We will only use the Default.aspx for this first example. Move on to the next chapter, for the obligatory "Hello, world!" example. 




      Next Chapter:

      News 8 June 2015

      News 7 June 2015

      aspnet introduction

      Introduction

      ASP.NET is a development framework for building web pages and web sites with HTML, CSS, JavaScript and server scripting.
      ASP.NET supports three different development models:
      1. Web Pages,

      2. MVC (Model View Controller), and 

      3.Web Forms
      ASP.NET is a programming framework developed by Microsoft
      for building powerful Web applications.

      Language Support

      ASP.NET has built-in support for three languages: Visual
      Basic (VB), C#, and Jscript.

      Web Forms

      ASP.NET Forms gives you the ability to create Web pages on
      the .NEST platform.

      Web Controls

      Standard Web Controls

      Label

      default.aspx
      protected void Button1_Click(object sender, EventArgs e)
          {
              if (TextBox1.Text != "")
              {
                  Response.Redirect("Page1.aspx?cname=" + TextBox1.Text);
              }
              else
              {
                  Label2.Text = "Please enter text in textbox";
              }
          }
      Page1.aspx
      protected void Page_Load(object sender, EventArgs e)
          {
              Label1.Text = Request.Params["cname"];
          }

      Saturday, June 6, 2015

      Multi-Threading

      MULTITHREADING

      Multithreading allows an application to divide tasks such that they work independently of each other to make the most efficient use of the processor and the user’s time. Threading is not always the right choice for all applications as they sometimes slows down the processing speed of the application.

      Thread

      Every application runs with at least one thread. A thread is nothing more than a process. On the computer, a thread is a process moving through time. The process performs sets of sequential steps, each step executing a line of code. The steps are sequential and take a given amount of time. The time it takes to complete a series of steps is the sum of the time it takes to perform each programming step.

      Multithreading applications

      For a long time, most programming applications were single threaded. That means there was only thread in the entire application. You could never do computation A until completing computation B. A multithreaded application allows you to run several threads, each thread running in its own process. So theoretically you can run computation A in one thread, and at the same time Computation B in another thread. At the same time you could run computation C, D in their own threads. Hence computation A, B, C and D would run concurrently. Theoretically, if all four computations took about the same time, you could finish you program in a quarter of the time it takes to run a single thread. 

      ThreadStart() and Thread() class

      using System.Threading;
      public class dummy
      {
      public static void prt()
      {
      System.Console.WriteLine("Hi");
      }
      }
      public class thread
      {
      public static void Main()
      {
      ThreadStart ts = new ThreadStart(dummy.prt);
      Thread t = new Thread(ts);
      System.Console.WriteLine("Before Start");
      t.Start();
      }
      }

      Start() method

      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      System.Console.WriteLine("Hi");
      }
      }
      public class thread
      {
      public static void Main()
      {
      dummy obj = new dummy();
      Thread t = new Thread (new ThreadStart(obj.prt));
      t.Start();
      }
      }

      2 threads running

      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      for (int i=0; i<=3; i++) { System.Console.WriteLine(i + " "); } } public void disp() { for(int i= 0; i<=3; i++) { System.Console.WriteLine(i + "..."); } } } public class thread { public static void Main() { dummy obj = new dummy(); Thread t = new Thread (new ThreadStart(obj.prt)); Thread t1 = new Thread(new ThreadStart(obj.prt)); t.Start(); t1.Start(); } }

      Sleep() method

      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      for (int i=0; i<=3; i++) { System.Console.WriteLine(i + " "); Thread.Sleep(500); } } public void disp() { for(int i= 0; i<=3; i++) { System.Console.WriteLine(i + "..."); Thread.Sleep(500); } } } public class thread { public static void Main() { dummy obj = new dummy(); Thread t = new Thread (new ThreadStart(obj.prt)); Thread t1 = new Thread(new ThreadStart(obj.prt)); t.Start(); t1.Start(); } }

      Name property

      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      for (int i=0; i<=3; i++) { Thread t2 = Thread.CurrentThread; System.Console.WriteLine(i + "," + t2.Name + " "); Thread.Sleep(500); } } } public class thread { public static void Main() { dummy obj = new dummy(); Thread t = new Thread (new ThreadStart(obj.prt)); Thread t1 = new Thread(new ThreadStart(obj.prt)); t.Name = "One"; t1.Name = "Two"; t.Start(); t1.Start(); } }

      Abort(), IsAlive() methods

      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      System.Console.WriteLine("Hi!");
      Thread.Sleep(10);
      }
      }
      public class thread
      {
      public static void Main()
      {
      dummy obj = new dummy();
      Thread t = new Thread (new ThreadStart(obj.prt));
      System.Console.WriteLine(t.IsAlive);
      t.Start();
      System.Console.WriteLine(t.IsAlive);
      t.Abort();
      System.Console.WriteLine(t.IsAlive);
      }
      }

      Running a thread till it is alive

      Example 1
      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      System.Console.WriteLine("Hi!");
      }
      }
      public class thread
      {
      public static void Main()
      {
      dummy obj = new dummy();
      Thread t = new Thread (new ThreadStart(obj.prt));
      t.Start();
      while (!t.IsAlive)
      System.Console.WriteLine("Hi");
      }
      }
      Example 2
      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      for (int i=0; i<=3; i++) System.Console.WriteLine("Hi!" + i + " "); } } public class thread { public static void Main() { dummy obj = new dummy(); Thread t = new Thread (new ThreadStart(obj.prt)); t.Start(); System.Console.WriteLine("Over"); } }

      Thread: Start(), Join()

      Example 1
      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      for (int i=0; i<=3; i++) System.Console.WriteLine("Hi!" + i + " "); } } public class thread { public static void Main() { dummy obj = new dummy(); Thread t = new Thread (new ThreadStart(obj.prt)); t.Start(); t.Join(); System.Console.WriteLine("Over"); } }
      Example 2
      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      for ( ; ; ) ;
      }
      }
      public class thread
      {
      public static void Main()
      {
      dummy obj = new dummy();
      Thread t = new Thread (new ThreadStart(obj.prt));
      t.Start();
      bool b = t.Join(10000);
      System.Console.WriteLine("Over " + b) ;
      }
      }
      Example 3
      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      System.Console.WriteLine("function running");
      }
      }
      public class thread
      {
      public static void Main()
      {
      dummy obj = new dummy();
      Thread t = new Thread (new ThreadStart(obj.prt));
      t.Start();
      Thread.Sleep(200);
      t.Abort();
      System.Console.WriteLine("Over ") ;
      Thread.Sleep(200);
      try
      {
      t.Start();
      }
      catch(ThreadStateException e)
      {
      System.Console.WriteLine("In Exception " + e);
      }
      }
      }

      ApartmentState

      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      System.Console.WriteLine("function running");
      }
      }
      public class thread
      {
      public static void Main()
      {
      dummy obj = new dummy();
      Thread t = new Thread (new ThreadStart(obj.prt));
      System.Console.WriteLine(t.ApartmentState);
      t.ApartmentState = ApartmentState.STA;
      t.Start();
      System.Console.WriteLine(t.ApartmentState);
      }
      }

      IsBackground property

      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      System.Console.WriteLine( "prt() " + Thread.CurrentThread.IsBackground);
      }
      }
      public class thread
      {
      public static void Main()
      {
      dummy obj = new dummy();
      Thread t = new Thread (new ThreadStart(obj.prt));
      System.Console.WriteLine("Main " + Thread.CurrentThread.IsBackground);
      t.Start();
      }
      }

      Creating a background thread

      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      for(int i=0; i<=100; i++) { System.Console.WriteLine( "prt() " + i); Thread.Sleep(100); } } } public class thread { public static void Main() { dummy obj = new dummy(); Thread t = new Thread (new ThreadStart(obj.prt)); System.Console.WriteLine("Main " + Thread.CurrentThread.IsBackground); t.IsBackground = true; t.Start(); Thread.Sleep(100); } }

      ThreadPriority enum

      Example 1
      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      for(int i=0; i<=10; i++) { System.Console.WriteLine(i + " "); Thread.Sleep(100); } } public void display() { for(int i=0; i<=10; i++) { System.Console.WriteLine(i + "..."); Thread.Sleep(100); } } } public class thread { public static void Main() { dummy obj = new dummy(); Thread t = new Thread (new ThreadStart(obj.prt)); Thread t1 = new Thread(new ThreadStart(obj.display)); System.Console.WriteLine(t.Priority); t.Priority = ThreadPriority.Highest; t1.Priority = ThreadPriority.Lowest; t.Start(); t1.Start(); } }
      Example 2
      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      try
      {
      System.Console.WriteLine("in prt()");
      for(; ; );
      }
      catch (System.Exception e)
      {
      System.Console.WriteLine("In abc Exception " + e.ToString());
      }
      finally
      {
      System.Console.WriteLine("in abc Finally");
      }
      }
      }

      public class thread
      {
      public static void Main()
      {
      dummy obj = new dummy();
      Thread t = new Thread (new ThreadStart(obj.prt));
      t.Start();
      Thread.Sleep(10);
      t.Abort();
      }
      }
      Example 3: 

      using System.Threading;
      public class dummy
      {
      public void prt()
      {
      try
      {
      System.Console.WriteLine("in prt()");
      for(; ; );
      }
      catch (System.Exception e)
      {
      System.Console.WriteLine("In abc Exception " + e.ToString());
      }
      finally
      {
      System.Console.WriteLine("in abc Finally");
      }
      }
      }
      public class thread
      {
      public static void Main()
      {
      dummy obj = new dummy();
      Thread t = new Thread (new ThreadStart(obj.prt));
      t.Abort();
      t.Start();
      }
      }

      Suspend(), Resume() methods using System.Threading;

      public class dummy
      {
      public void prt()
      {
      for(int i=1; i<=10; i++) { System.Console.Write(i + " "); Thread.Sleep(100); } } } public class thread { public static void Main() { dummy obj = new dummy(); Thread t = new Thread (new ThreadStart(obj.prt)); t.Start(); Thread.Sleep(10); t.Suspend(); System.Console.WriteLine("\n After Suspend"); Thread.Sleep(10); System.Console.WriteLine("Before Resume"); t.Resume(); } }

      Mutex

      When two or more threads need to access a shared resource at the same time, the system needs to be in synchronization mechanism to ensure that only one thread at a time uses the resource. Mutex is a synchronization primitive that grants exclusive access to the shared resource to only one thread. If a thread acquires a mutex, the second thread that wants to acquire that mutex is suspended until the first thread releases the mutex. using System;
      using System.Threading;
      class Test
      {
      private static Mutex mut = new Mutex();
      private const int numIterations = 1;
      private const int numThreads = 3;
      static void Main()
      {
      for (int i = 0; i < numThreads; i++) { Thread myThread = new Thread(new ThreadStart(MyThreadProc)); myThread.Name = String.Format("Thread{0}", i + 1); myThread.Start(); } } private static void MyThreadProc() { for (int i = 0; i < numIterations; i++) { UseResource(); } } private static void UseResource() { mut.WaitOne(); Console.WriteLine("{0} has entered the protected area",Thread.CurrentThread.Name); Thread.Sleep(500); Console.WriteLine("{0} is leaving the protected area\r\n",Thread.CurrentThread.Name); mut.ReleaseMutex(); } }

      Mutex - Infinite wait

      using System.Threading;
      public class thread
      {
      static Mutex m;
      public static void Main()
      {
      m = new Mutex(true, "aptech");
      thread obj = new thread();
      Thread t = new Thread(new ThreadStart(thread.prt));
      t.Start();
      }
      public static void prt()
      {
      System.Console.WriteLine("thread start");
      m.WaitOne();
      System.Console.WriteLine("thread end");
      }
      }
      Mutexes using System.Threading;
      public class thread
      {
      static Mutex m;
      public static void Main()
      {
      m = new Mutex(false, "aptech");
      thread obj = new thread();
      System.Console.WriteLine("thread start");
      m.WaitOne();
      System.Console.WriteLine("thread end");
      }
      }

      Locking

      using System;
      using System.Threading;
      class threadSafety
      {
      public static object Compute = new object();
      public static int ValOne, ValTwo;
      static void Divide()
      {
      ValOne = 45;
      ValTwo = 8;
      lock (Compute)
      {
      if (ValOne != 0)
      Console.WriteLine(ValOne / ValTwo);
      ValTwo = 0;
      }
      }
      public static void Main()
      {
      Divide();
      }
      }