Click here to Skip to main content
15,922,145 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to serialize Struct such as using System.Web.UI.WebControls.Unit Pin
leppie14-Mar-06 20:14
leppie14-Mar-06 20:14 
QuestionControlling wav balance Pin
Superwill14-Mar-06 12:50
Superwill14-Mar-06 12:50 
AnswerRe: Controlling wav balance Pin
mav.northwind15-Mar-06 2:18
mav.northwind15-Mar-06 2:18 
GeneralRe: Controlling wav balance Pin
Superwill15-Mar-06 3:58
Superwill15-Mar-06 3:58 
QuestionFront Page Extensions Error Pin
puri_shah14-Mar-06 11:38
puri_shah14-Mar-06 11:38 
QuestionHow to print a form in C# Pin
JuJAngel14-Mar-06 10:01
JuJAngel14-Mar-06 10:01 
QuestionHow to disable IE toolbar buttons Pin
sreejnarayan14-Mar-06 9:54
sreejnarayan14-Mar-06 9:54 
QuestionThread's Pin
CiberwizZ14-Mar-06 9:08
CiberwizZ14-Mar-06 9:08 
using System;
using System.Threading;
using System.IO;

namespace Threaded
{
public class me
{
public string texto;
public string path;

public string Path { get { return path; } set { path = value; } }
public string Texto { get { return texto; } set { texto = value; } }

public me() { }

public void copia()
{
Stream fix;
for (int i=0 ; i < texto.Length ; i++)
lock (this)
{
fix = new FileStream(path, FileMode.Create);
fix.WriteByte((byte) texto[i]);
fix.Close();
Monitor.Pulse(this);
if (i < texto.Length)
Monitor.Wait(this);
}
}

}

class teste
{
public static void Main()
{

string text;
me eu = new me();
me eu2 = new me();

text= Console.ReadLine();

eu.Path = "1.txt";
eu.Texto = text;

eu2.Path = "2.txt";
eu2.Texto = text;

Thread a = new Thread(new ThreadStart(eu.copia));

a.Start();
eu2.copia();

}
}
}

the objective of this program is to write a texto to 2 files using threads :S the problem is that it stucks after writing the first letter, i believe it's a synchronization bug, but i really can't see where the problem is... please help.
(i didn't know which part of the code that contains the bug so i posted all of it )

_________________________________________________________________________________
"There is no great genius without some touch of madness." - Seneca (5 BC - 65 AD)
AnswerRe: Thread's Pin
Ed.Poore14-Mar-06 9:46
Ed.Poore14-Mar-06 9:46 
QuestionRe: Thread's Pin
CiberwizZ14-Mar-06 10:14
CiberwizZ14-Mar-06 10:14 
AnswerRe: Thread's Pin
Ed.Poore14-Mar-06 10:41
Ed.Poore14-Mar-06 10:41 
GeneralRe: Thread's Pin
CiberwizZ14-Mar-06 10:52
CiberwizZ14-Mar-06 10:52 
QuestionListView problems Pin
Authorof2214-Mar-06 8:27
Authorof2214-Mar-06 8:27 
QuestionRe: ListView problems Pin
Ed.Poore14-Mar-06 9:47
Ed.Poore14-Mar-06 9:47 
AnswerRe: ListView problems Pin
Authorof2214-Mar-06 10:11
Authorof2214-Mar-06 10:11 
GeneralRe: ListView problems Pin
Dan Neely14-Mar-06 10:35
Dan Neely14-Mar-06 10:35 
GeneralRe: ListView problems Pin
Ed.Poore14-Mar-06 10:39
Ed.Poore14-Mar-06 10:39 
GeneralRe: ListView problems Pin
Ed.Poore14-Mar-06 10:39
Ed.Poore14-Mar-06 10:39 
GeneralRe: ListView problems Pin
Authorof2215-Mar-06 5:04
Authorof2215-Mar-06 5:04 
GeneralRe: ListView problems Pin
Ed.Poore15-Mar-06 5:40
Ed.Poore15-Mar-06 5:40 
QuestionTreeView index Pin
Authorof2214-Mar-06 8:23
Authorof2214-Mar-06 8:23 
AnswerRe: TreeView index Pin
Ed.Poore14-Mar-06 9:54
Ed.Poore14-Mar-06 9:54 
GeneralRe: TreeView index Pin
Authorof2214-Mar-06 10:05
Authorof2214-Mar-06 10:05 
GeneralRe: TreeView index Pin
Ed.Poore14-Mar-06 10:25
Ed.Poore14-Mar-06 10:25 
GeneralRe: TreeView index Pin
Authorof2215-Mar-06 2:46
Authorof2215-Mar-06 2:46 

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.