C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Thread Synchronisation in .Net using C#


Posted Date: 09 Sep 2008    Resource Type: Code Snippets    Category: Threading

Posted By: Satyanarayan SushilKumar Bajoria       Member Level: Diamond
Rating:     Points: 10



This code demonstrate how to synchronise threads in .NET using C#


using System.Threading;
class Bank
{

Mutex m=new Mutex();
public void withdraw()
{

m.WaitOne();//this method will allow only one thread at a time
MessageBox.Show("From withdraw");
m.ReleaseMutex();//this methos is releasing executed thread features

}
}
private void button1_Click(Object ender,EventArgs e)
{
Bank obj=new Bank();
ThreadStart ts1=new ThreadStart(obj.withdraw);
Thread t1=new Thread(ts1);
Thread t2=new Thread(ts1);
t1.Start();
t2.Start();
}


Regards
S.S.Bajoria




Responses

Author: AmitChoudhary    10 Sep 2008Member Level: Bronze   Points : 2
Hi,
Where is ts2 declared ?
Have't you execucuted code without posting it ?
Pls run at least once before u post it on live ,
Even after declaration code will give error on

ThreadStart ts1=new ThreadStart(obj.withdraw());

don't simply put garbage for any body..

Thanks,
Amit Choudhary




Author: Satyanarayan SushilKumar Bajoria    11 Sep 2008Member Level: Diamond   Points : 1
Hi,

Sorry to all of you.Now i corrected the code and also execute it its running.

I really apololizes for that.

Regards
S.S.Bajoria


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
MultiThreading in .Net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: BackGroundWorker Control
Previous Resource: Threading
Return to Discussion Resource Index
Post New Resource
Category: Threading


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

SPOC

Contact Us    Privacy Policy    Terms Of Use