TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Threading in c# .net (http://forums.techarena.in/software-development/1386325.htm)

Athreya 12-01-2011 03:21 PM

Threading in c# .net
 
I am desktop application developer. I am currently working on c#. Nowadays I am working on a live project for one local company. Yesterday I come across one scenario where there is need to run multiple processes simultaneously just like keeping an process to running state but in background and performing other operations on front end. Is there any way to achieve same thing in case of programming in C#.net.

Steyn 12-01-2011 03:27 PM

Re: Threading in c# .net
 
Yes! I have a solution for keeping number of processes in background in running state. C# supports parallel execution of code through multithreading. When any process starts on a system it is treated as parent thread or primary thread. This primary thread process may run along with no. of child threads during working. A thread is an independent execution path, able to run simultaneously with other threads. A C# client program starts in single thread created automatically by CLR. CLR assigns each thread its own memory stack so that local variables are kept separate. So it is possible to keep number of processes simultaneously by assigning each process to new individual thread.

Dwarner 12-01-2011 03:28 PM

Re: Threading in c# .net
 
Windows also follow the concept of threading to provide us the facility of multitasking. For using multitasking in your project you just need to add two namespaces in your solution which provides all the keywords and methods which you required to perform threading in your application. The namespaces that you need to add in your solutions are:-
  1. System
  2. System. Threading
After inheriting both these namespaces you just need to create an object of thread class and after creating an object pass the method that you want to execute along that thread.

Vandam 12-01-2011 03:29 PM

Re: Threading in c# .net
 
After starting the thread its "IsAlive" property returns true until the point where the thread ends. A thread ends when the delegate passed to the Thread’s constructor finishes executing. Once ended, a thread cannot start. But yes you can keep it as pending using Thread class sleep property. If more than one thread is working on a common or shared object than you have to use proper locking mechanism to avoid accident between two working threads. You can use conditional statements to check locking.


All times are GMT +5.5. The time now is 12:43 AM.