Breaking News

Thursday 24 October 2013

Thread State

Thread State :

every object has its state. For example : water is found in three states , such as solid , liquid , and gas and it can be transform from one state to another. In the same way , threads also have their states and can be transformed from one state to another. The state of thread determines its actual status at a given point of time. you can determine state of a thread by the ThreadState property of the Thread Class.


States of threads:


Name
Description
Running
Refers to a state in which the thread is in the execution mode.
StopRequested
Refers to a state in which a thread is requested to stop its execution.
SuspendRequested
Refers to a state in which a thread is required to suspend its execution.
Background
Refers to a state in which a thread is execute as a background thread , as opposed to foreground thread.
Unstarted
Refers to a state in which  the start() method of the thread class has not yet been invoked.
Stopped
Refers to a state in which a thread has already stopped executing.
WaitSleepJoin
Refers to a state that occurs when the wait() , sleep() , and join() method are simultaneously invoked. A thread in this state stops executing and is considered  to be blocked.
Suspended
Refers to a state in which a thread has been suspended.
AbortRequsted
Refers to state in which a thread is required to stop its functioning permanently.
Abort
Refers to a state in which a thread is considered to be dead forever.


showing the code of the Thread State application:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace thread_state.cs
{
    class Program
    {
        static Thread firstthread;
        static Thread secondthread;
        static Thread thirdthread;
        static void Main(string[] args)
        {
            firstthread = new Thread(firstfunction);
            secondthread = new Thread(secondfunction);
            thirdthread = new Thread(thirdfunction);
            firstthread.Name = "first thread";
            secondthread.Name = "second thread";
            thirdthread.Name = "third thread";
            StateOfThread("main() before starting the threads..");
            firstthread.Start();
            secondthread.Start();
            thirdthread.Start();
            StateOfThread("main() before ending the threads..");
        }
        // writting a function for determining the state of the thread
        public static void StateOfThread(string position)
        {
            Console.WriteLine("\n in" + position);
            Console.WriteLine("thread name :\t" + firstthread.Name + "thread state\t" + firstthread.ThreadState);
            Console.WriteLine("thread name :\t" + secondthread.Name + "thread state\t" + secondthread.ThreadState);
            Console.WriteLine("thread name :\t" + thirdthread.Name + "thread state\t" + thirdthread.ThreadState);
        }
        public static void firstfunction()
        {
            for (int num = 1; num <= 5; num++)
            {
                Console.WriteLine("first thread displays\t" + num);
                Thread.Sleep(2000);
            }
            StateOfThread("firstfunction()");
        }
        public static void secondfunction()
        {
            for (int num = 1; num <= 5; num++)
            {
                Console.WriteLine("second thread displays\t" + num);
                Thread.Sleep(5000);
            }
            StateOfThread("secondfunction()\t");
        }
        public static void thirdfunction()
        {
            for (int num = 1; num <= 5; num++)
            {
                Console.WriteLine("third thread displays\t" + num);
                Thread.Sleep(7000);
            } 
            StateOfThread("thirdfunction()");
            Console.ReadKey();
        }
    }

}

output :




Read more ...

Thread Priorities in C#

Depending upon the order and importance of the task assigned to threads in a multitasking environment , the priority levels of threads is determined. The thread having the higher priority is executed more frequently than one that has a lower priority.

priorities of a thread:

Name
Description
Lowest
Refers to the last important priority level that can be assigned to a thread. A thread with this priority can be scheduled after thread with any other priority.
BelowNormal
Refers to the  priority level that is just below the normal level. The thread with this can be scheduled after thread having the normal priority and before those with the lowest priority.
Normal
Refers to the priority level that is neither lowest nor highest. The thread with this priority level can be scheduled after thread with the AboveNormal priority and before those with the BelowNormal priority. All the threads have the Normal priority by default.
AboveNoraml
Refer the priority level that is just below the highest level. The thread with this priority can be scheduled after threads with the highest priority and before those with the Normal priority.
Highest
Refers to the most important priority level that can be assigned to a thread. The thread with this priority can be scheduled before thread with any other priority.




























Note : The thread priority is set to Normal , by default.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace thread_priprity.cs
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread firstthread = new Thread(firstfunction);
            Thread secondthread = new Thread(secondfunction);
            Thread thirdthread = new Thread(thirdfunction);
            firstthread.Name = "first thread";
            secondthread.Name = "second thread";
            thirdthread.Name = "third thread";
            // setting priorities for threads
            firstthread.Priority = ThreadPriority.Lowest;
            secondthread.Priority = ThreadPriority.Highest;
            thirdthread.Priority = ThreadPriority.AboveNormal;
            Console.WriteLine("thread starts..");
            firstthread.Start();
            secondthread.Start();
            thirdthread.Start();
        }
        public static void firstfunction()
        {
            for (int number = 1; number <= 5; number++)
            {
                Console.WriteLine("first thread displays" + number);
                Thread.Sleep(3000);
            } 
        }
        public static void secondfunction()
        {
            for (int number = 1; number <= 5; number++)
            {
                Console.WriteLine("second thread displays" + number);
                Thread.Sleep(7000);
            }
        }
        public static void thirdfunction()
        {
            for (int number = 1; number <= 5; number++)
            {
                Console.WriteLine("third thread displays" + number);
                Thread.Sleep(10000);

            } Console.ReadKey();
        }
    }
}

output :



Read more ...

How to download windows 8.1

I know every body want to download windows 8.1 , so let's follow these steps and you can able to download windows 8.1.....
for downloading windows on your computer or PC you need to follow these steps and I hope this is your great experience with windows 8.1....

step 1 :  for downloading windows 8.1 just follow the link given blow :


when you click on the given link , a new window will open as the following figure given blow ;


step 2 : After clicked on the link , read the instruction carefully given blow and select a version of windows and click on the GET STARTED NOW button given after the selection bar...



step 3 : After clicked on the GET STARTED NOW button a new window will appear as given blow..




now , you need to Sign in you Microsoft account to complete your step...

step 4 : After this , a new window will appear on your screen as given blow ;


now , read all the following requirement and fill all the empty box.

step 5 : After filling the all empty boxes , A new window will appear on your screen as given blow and read the following steps on your screen..


After reading the all steps now , click on the download the installer 

step 6 : now you need to run your downloaded application and your downloading would be start....






more about windows 8.1 :





Read more ...
© 2013 Post by repter_x