Click here to Skip to main content
15,890,845 members
Home / Discussions / C#
   

C#

 
AnswerRe: Docking a Windows Form to the edge of a screen Pin
Jordanwb9-Nov-08 2:57
Jordanwb9-Nov-08 2:57 
GeneralRe: Docking a Windows Form to the edge of a screen Pin
Eddy Vluggen9-Nov-08 22:02
professionalEddy Vluggen9-Nov-08 22:02 
QuestionDoes any one know about how to code for automated shift scheduling using genetic algorithm?? Pin
hiewmoi8-Nov-08 11:01
hiewmoi8-Nov-08 11:01 
QuestionColour clicker Pin
boberick28-Nov-08 1:41
boberick28-Nov-08 1:41 
GeneralRe: Colour clicker Pin
Luc Pattyn8-Nov-08 2:53
sitebuilderLuc Pattyn8-Nov-08 2:53 
AnswerRe: Colour clicker Pin
Muammar©8-Nov-08 23:59
Muammar©8-Nov-08 23:59 
QuestionClosing sockets in asynchronous TCP server Pin
Metal767-Nov-08 22:42
Metal767-Nov-08 22:42 
AnswerRe: Closing sockets in asynchronous TCP server Pin
Nicholas Butler8-Nov-08 1:01
sitebuilderNicholas Butler8-Nov-08 1:01 
Hi Andrea,

I was hoping that Shutdown would be thread-safe. Obviously not, so you'll have to implement some control synchronization yourself.

You can do this with a ReaderWriterLock - or preferably ReaderWriterLockSlim, if you are targeting .NET 3.5. Something like this:

// in your NetworkServer class
private volatile bool quit = false;
private ReaderWriterLock rwl = new ReaderWriterLock();

// in OnClientConnect
Socket clientSocket = null;
rwl.AcquireReaderLock(-1);// -1 == Timeout.Infinite
try
{
  if ( quit ) return;
  clientSocket = serverSocket.EndAccept(state);
}
finally
{
  rwl.ReleaseReaderLock();
}

// same ( reader lock ) in OnClientRead - wrap the call to EndReceive

// in Shutdown
rwl.AcquireWriterLock(-1);
try
{
  quit = true;

  foreach ( var client in clientList )
  {
    client.Socket.Shutdown();
    client.Socket.Dispose();
  }
}
finally
{
  rwl.ReleaseWriterLock();
}

Does that make sense?

Nick

----------------------------------
Be excellent to each other Smile | :)

GeneralRe: Closing sockets in asynchronous TCP server Pin
Metal768-Nov-08 1:10
Metal768-Nov-08 1:10 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Nicholas Butler8-Nov-08 2:39
sitebuilderNicholas Butler8-Nov-08 2:39 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Metal768-Nov-08 23:16
Metal768-Nov-08 23:16 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Nicholas Butler9-Nov-08 3:41
sitebuilderNicholas Butler9-Nov-08 3:41 
AnswerRe: Closing sockets in asynchronous TCP server Pin
Mark Salsbery9-Nov-08 7:46
Mark Salsbery9-Nov-08 7:46 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Metal769-Nov-08 9:09
Metal769-Nov-08 9:09 
GeneralRe: Closing sockets in asynchronous TCP server Pin
Mark Salsbery9-Nov-08 9:43
Mark Salsbery9-Nov-08 9:43 
QuestionCan i run windows application in Linux ? Pin
Krishnraj7-Nov-08 22:15
Krishnraj7-Nov-08 22:15 
AnswerRe: Can i run windows application in Linux ? Pin
Perspx7-Nov-08 22:33
Perspx7-Nov-08 22:33 
AnswerRe: Can i run windows application in Linux ? Pin
#realJSOP7-Nov-08 23:56
mve#realJSOP7-Nov-08 23:56 
GeneralRe: Can i run windows application in Linux ? Pin
Krishnraj1-Dec-08 1:46
Krishnraj1-Dec-08 1:46 
AnswerRe: Can i run windows application in Linux ? Pin
Dave Kreskowiak8-Nov-08 5:56
mveDave Kreskowiak8-Nov-08 5:56 
AnswerRe: Can i run windows application in Linux ? Pin
Atif Shahbaz8-Nov-08 6:11
Atif Shahbaz8-Nov-08 6:11 
AnswerRe: Can i run windows application in Linux ? Pin
Paul Conrad8-Nov-08 13:05
professionalPaul Conrad8-Nov-08 13:05 
QuestionAccess to soap WebServer without "Add Web Reference" Option Pin
Patricio Tapia7-Nov-08 22:01
Patricio Tapia7-Nov-08 22:01 
AnswerRe: Access to soap WebServer without "Add Web Reference" Option Pin
Wendelius8-Nov-08 1:05
mentorWendelius8-Nov-08 1:05 
QuestionBackgroundWorker and command line exe: what DoWork deals with? Pin
LordZoster7-Nov-08 20:52
LordZoster7-Nov-08 20:52 

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.