Click here to Skip to main content
16,006,902 members
Home / Discussions / C#
   

C#

 
GeneralRe: retrieving http sites (frames) Pin
S. Senthil Kumar16-Jun-05 3:45
S. Senthil Kumar16-Jun-05 3:45 
GeneralRe: retrieving http sites (frames) Pin
alexffm16-Jun-05 3:54
alexffm16-Jun-05 3:54 
GeneralCompiling C# Code at runtime Pin
Sumit Domyan16-Jun-05 2:33
Sumit Domyan16-Jun-05 2:33 
GeneralRe: Compiling C# Code at runtime Pin
tom_dx16-Jun-05 2:55
tom_dx16-Jun-05 2:55 
GeneralRe: Compiling C# Code at runtime Pin
S. Senthil Kumar16-Jun-05 3:27
S. Senthil Kumar16-Jun-05 3:27 
GeneralRe: Compiling C# Code at run time Pin
eggie516-Jun-05 5:38
eggie516-Jun-05 5:38 
GeneralRe: Compiling C# Code at run time Pin
S. Senthil Kumar16-Jun-05 5:42
S. Senthil Kumar16-Jun-05 5:42 
QuestionCan someone suggest me style improvements? Pin
Alex Cutovoi16-Jun-05 1:58
Alex Cutovoi16-Jun-05 1:58 
Hi guys, I 've made a simple program that access a resource and read and write it. The program works fine, but I would like to know if my code is good or there is a better way to do the same.

Thanks a lot for helping me :->



using System;
using System.Collections;
using System.Threading;

namespace ReadersAndWriters
{
///
/// Summary description for Class1.
///

public class BookSeats
{
private bool bAccess = true;
public SortedList Seats = new SortedList();
public BookSeats()
{
for(int i = 0 ; i <= 9 ; i++)
{
Seats.Add(i, 0);
}
}
public int this[int iIndex]
{
get
{
if(!bAccess)
{
Monitor.Wait(this);
}
return (int) Seats[iIndex];
}
set
{
if(bAccess)
{
bAccess = false;
lock(this)
{
Seats[iIndex] = value;
bAccess = true;
Console.WriteLine("Thread {0} acionada", Thread.CurrentThread.Name);
Monitor.Pulse(this);
}
}
else
{
Monitor.Wait(this);
}
}
}
}

public class Client
{
private Random rGen = new Random();
private int iSeat = 0;
private BookSeats m_BookSeats;
public Client(BookSeats Seats)
{
m_BookSeats = Seats;
iSeat = rGen.Next(0, 9);
}
public void MakeReservation()
{
m_BookSeats[iSeat] = 1;
}
public void CancelReservation()
{
m_BookSeats[iSeat] = 0;
}
public void QueryReservation()
{
for(int i = 0 ; i < m_BookSeats.Seats.Count ; i++)
{
if(m_BookSeats[i] == 0)
{
Console.WriteLine("Thread {0} lendo", Thread.CurrentThread.Name);
}
else
{
Console.WriteLine("Lugar reservado");
}
}
}
}
class Class1
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
BookSeats Seats = new BookSeats();
Client ClientOne = new Client(Seats);
Client ClientTwo = new Client(Seats);
Thread ClientOneMR = new Thread(new ThreadStart(ClientOne.MakeReservation));
ClientOneMR.Name = "Reserva Cliente 1";
Thread ClientTwoMR = new Thread(new ThreadStart(ClientTwo.MakeReservation));
ClientTwoMR.Name = "Reserva Cliente 2";
//Thread ClientOneCR = new Thread(new ThreadStart(ClientOne.CancelReservation));
//ClientOneCR.Name = "Cancela Cliente 1";
//Thread ClientTwoCR = new Thread(new ThreadStart(ClientTwo.CancelReservation));
//ClientTwoCR.Name = "Cancela Cliente 2";
Thread ClientOneQR = new Thread(new ThreadStart(ClientOne.QueryReservation));
ClientOneQR.Name = "Consulta Cliente 1";
Thread ClientTwoQR = new Thread(new ThreadStart(ClientTwo.QueryReservation));
ClientTwoQR.Name = "Consulta Cliente 2";
ClientOneMR.Start();
ClientTwoMR.Start();
//ClientOneCR.Start();
//ClientTwoCR.Start();
ClientOneQR.Start();
ClientTwoQR.Start();
}
}
}
GeneralSQLDMO Create Database in C# Pin
gordsh16-Jun-05 1:39
gordsh16-Jun-05 1:39 
QuestionHow to write Installer for a executable file Pin
pakFari16-Jun-05 1:32
pakFari16-Jun-05 1:32 
AnswerRe: How to write Installer for a executable file Pin
nemopeti16-Jun-05 3:55
nemopeti16-Jun-05 3:55 
AnswerRe: How to write Installer for a executable file Pin
S. Senthil Kumar16-Jun-05 5:05
S. Senthil Kumar16-Jun-05 5:05 
GeneralRe: How to write Installer for a executable file Pin
pakFari16-Jun-05 20:49
pakFari16-Jun-05 20:49 
GeneralOpen Graphic files in real PixelFormat Pin
Alpini16-Jun-05 1:01
Alpini16-Jun-05 1:01 
GeneralRe: Open Graphic files in real PixelFormat Pin
Daniel Turini16-Jun-05 3:38
Daniel Turini16-Jun-05 3:38 
GeneralRe: Open Graphic files in real PixelFormat Pin
Alpini16-Jun-05 4:32
Alpini16-Jun-05 4:32 
GeneralRe: Open Graphic files in real PixelFormat Pin
Dave Kreskowiak16-Jun-05 4:47
mveDave Kreskowiak16-Jun-05 4:47 
GeneralRe: Open Graphic files in real PixelFormat Pin
Alpini16-Jun-05 9:22
Alpini16-Jun-05 9:22 
GeneralMouseWheel Event Pin
Anonymous16-Jun-05 0:41
Anonymous16-Jun-05 0:41 
GeneralRe: MouseWheel Event Pin
Marc Clifton16-Jun-05 1:23
mvaMarc Clifton16-Jun-05 1:23 
QuestionAdd-in, how to work with it? Pin
Khoa Bui15-Jun-05 23:28
Khoa Bui15-Jun-05 23:28 
AnswerRe: Add-in, how to work with it? Pin
Werdna16-Jun-05 4:55
Werdna16-Jun-05 4:55 
GeneralCrystal report and C# Pin
jeya_00715-Jun-05 23:16
jeya_00715-Jun-05 23:16 
QuestionListView - some kind of a scroll event? Pin
iliyang15-Jun-05 22:55
iliyang15-Jun-05 22:55 
Questionwhat is the difference between Property and Public Field? Pin
Khoa Bui15-Jun-05 22:51
Khoa Bui15-Jun-05 22:51 

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.