Click here to Skip to main content
15,887,404 members
Home / Discussions / C#
   

C#

 
GeneralRe: getting data over website Pin
J4amieC18-Nov-10 5:40
J4amieC18-Nov-10 5:40 
GeneralRe: getting data over website Pin
Lutosław18-Nov-10 6:56
Lutosław18-Nov-10 6:56 
GeneralRe: getting data over website Pin
SantokhSingh18-Nov-10 17:41
SantokhSingh18-Nov-10 17:41 
QuestionGrid view Caption Pin
4anusha417-Nov-10 19:57
4anusha417-Nov-10 19:57 
AnswerRe: Grid view Caption Pin
Pete O'Hanlon17-Nov-10 23:07
mvePete O'Hanlon17-Nov-10 23:07 
QuestionThreading in C# Pin
Anil Kumar.Arvapalli17-Nov-10 19:29
Anil Kumar.Arvapalli17-Nov-10 19:29 
AnswerRe: Threading in C# Pin
Abhinav S17-Nov-10 20:56
Abhinav S17-Nov-10 20:56 
GeneralRe: Threading in C# Pin
Anil Kumar.Arvapalli17-Nov-10 23:49
Anil Kumar.Arvapalli17-Nov-10 23:49 
thanks for ur reply...I have tried it with lock(object) but it is not working... Iam sending my code please go though it once and let me know, where i went wrong.

private void Form1_Load(object sender, EventArgs e)
{
try
{

sw = new StreamWriter("D:\\Threading.txt");
ThreadStart Thrdst = new ThreadStart(Thread1);
Thread t = new Thread(Thrdst);
t.Start();

ThreadStart Thrdstt = new ThreadStart(Thread2);
Thread tt = new Thread(Thrdstt);
tt.Start();

ThreadStart Thrdsttt = new ThreadStart(Thread3);
Thread ttt = new Thread(Thrdsttt);
ttt.Start();
}
catch (Exception err)
{
label1.Text = err.Message.ToString();
}
//Spawnning 3 Threads on form load..


private void Thread1()
{
Thread1 t1 = new Thread1();
t1.ThreadWriter(sw);
}
private void Thread2()
{
Thread2 t2 = new Thread2();
t2.ThreadWriter(sw);

}
private void Thread3()
{
Thread3 t3 = new Thread3();
t3.ThreadWriter(sw);
}
-------------------------------------------------------------------------------------------------------------------------
And i have three diferent clasees which write to text file...

class Thread1
{
private Object thisLock;



public void ThreadWriter(StreamWriter sw)
{

thisLock = new Object();
lock (this)
{
for (int i = 0; i < 10; i++)
{
sw.WriteLine("Thread 1 = " + i);
Thread.Sleep(100);


}
sw.Close();
}
}
}
The other two are almost similar...


Output is:-
--------------
Thread 1 = 0
Thread 2 = 0
Thread 3 = 0
Thread 1 = 1
Thread 3 = 1
Thread 2 = 1
Thread 1 = 2
Thread 3 = 2
Thread 2 = 2
Thread 1 = 3
Thread 3 = 3
Thread 2 = 3
Thread 1 = 4
Thread 3 = 4
Thread 2 = 4
Thread 1 = 5
Thread 2 = 5
Thread 3 = 5
Thread 1 = 6
Thread 3 = 6
Thread 2 = 6
Thread 1 = 7
Thread 3 = 7
Thread 2 = 7
Thread 1 = 8
Thread 3 = 8
Thread 2 = 8
Thread 1 = 9
Thread 3 = 9
Thread 2 = 9

Please help me out.. Thanks in Advance...
GeneralRe: Threading in C# Pin
Dave Kreskowiak18-Nov-10 1:52
mveDave Kreskowiak18-Nov-10 1:52 
GeneralRe: Threading in C# Pin
_Erik_18-Nov-10 2:59
_Erik_18-Nov-10 2:59 
GeneralRe: Threading in C# Pin
Anil Kumar.Arvapalli18-Nov-10 3:53
Anil Kumar.Arvapalli18-Nov-10 3:53 
GeneralRe: Threading in C# [modified] Pin
_Erik_18-Nov-10 4:08
_Erik_18-Nov-10 4:08 
GeneralRe: Threading in C# Pin
Anil Kumar.Arvapalli18-Nov-10 17:54
Anil Kumar.Arvapalli18-Nov-10 17:54 
AnswerRe: Threading in C# Pin
Pete O'Hanlon17-Nov-10 22:05
mvePete O'Hanlon17-Nov-10 22:05 
QuestionPlot histogram Pin
pancakeleh17-Nov-10 18:47
pancakeleh17-Nov-10 18:47 
AnswerRe: Plot histogram Pin
Dr.Walt Fair, PE17-Nov-10 19:28
professionalDr.Walt Fair, PE17-Nov-10 19:28 
GeneralRe: Plot histogram [modified] Pin
pancakeleh17-Nov-10 19:41
pancakeleh17-Nov-10 19:41 
GeneralRe: Plot histogram Pin
Richard MacCutchan18-Nov-10 1:36
mveRichard MacCutchan18-Nov-10 1:36 
GeneralRe: Plot histogram Pin
pancakeleh18-Nov-10 15:02
pancakeleh18-Nov-10 15:02 
Questiontree visualization Pin
pstsp91117-Nov-10 18:40
pstsp91117-Nov-10 18:40 
AnswerRe: tree visualization Pin
Alan Balkany23-Nov-10 3:59
Alan Balkany23-Nov-10 3:59 
QuestionMerge image problem Pin
pancakeleh17-Nov-10 15:48
pancakeleh17-Nov-10 15:48 
AnswerRe: Merge image problem Pin
Dave Kreskowiak17-Nov-10 16:00
mveDave Kreskowiak17-Nov-10 16:00 
GeneralRe: Merge image problem Pin
pancakeleh17-Nov-10 16:03
pancakeleh17-Nov-10 16:03 
GeneralRe: Merge image problem Pin
fjdiewornncalwe17-Nov-10 16:32
professionalfjdiewornncalwe17-Nov-10 16:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.