Click here to Skip to main content
15,867,330 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralReversing time, without a flux capacitor Pin
Gary R. Wheeler17-Jan-13 4:03
Gary R. Wheeler17-Jan-13 4:03 
Our C# application uses TCP/IP sockets for interprocess communication. I use the Socket class asynchronous methods to process received messages, something like this:
// start initial receive operation
s.BeginReceive(...,OnReceive);
...
void OnReceive(...)
{
   lock(...)
   {
       // fetch incoming message
       ...
       // start next receive operation
       s.BeginReceive(...,OnReceive)
   }
   // process received message outside of lock to avoid holding it for a long time
   ...
}
I discovered that the OnReceive was being called recursively under heavy traffic conditions, resulting in messages being processed in reverse order for brief periods D'Oh! | :doh: Sigh | :sigh: . The solution went something like this:
// start initial receive operation
s.BeginReceive(...,OnReceive);
...
void OnReceive(...)
{
   lock(...)
   {
       // fetch incoming message
       ...
   }
   // process received message outside of lock to avoid holding it for a long time
   ...
   // start next receive operation
   s.BeginReceive(...,OnReceive)
}
The time-reversing version has been in the product since 2008, and I only discovered it a week ago. One petard-wedgie, coming up.
Software Zen: delete this;

GeneralRe: Reversing time, without a flux capacitor Pin
LloydA11117-Jan-13 5:57
LloydA11117-Jan-13 5:57 
GeneralRe: Reversing time, without a flux capacitor Pin
Gary R. Wheeler17-Jan-13 9:25
Gary R. Wheeler17-Jan-13 9:25 
GeneralRe: Reversing time, without a flux capacitor Pin
LloydA11117-Jan-13 11:40
LloydA11117-Jan-13 11:40 
GeneralRe: Reversing time, without a flux capacitor Pin
BobJanova21-Jan-13 4:52
BobJanova21-Jan-13 4:52 
GeneralRe: Reversing time, without a flux capacitor Pin
Brisingr Aerowing17-Jan-13 14:25
professionalBrisingr Aerowing17-Jan-13 14:25 
GeneralRe: Reversing time, without a flux capacitor Pin
BobJanova21-Jan-13 4:56
BobJanova21-Jan-13 4:56 
GeneralRe: Reversing time, without a flux capacitor Pin
englebart23-Jan-13 3:35
professionalenglebart23-Jan-13 3:35 
GeneralRe: Reversing time, without a flux capacitor Pin
Gary R. Wheeler23-Jan-13 11:45
Gary R. Wheeler23-Jan-13 11:45 
GeneralRe: Reversing time, without a flux capacitor Pin
Member 793197823-Jan-13 5:44
professionalMember 793197823-Jan-13 5:44 
GeneralRe: Reversing time, without a flux capacitor Pin
Gary R. Wheeler23-Jan-13 11:58
Gary R. Wheeler23-Jan-13 11:58 
JokeRe: Reversing time, without a flux capacitor Pin
RafagaX23-Jan-13 6:21
professionalRafagaX23-Jan-13 6:21 
GeneralRe: Reversing time, without a flux capacitor Pin
Paulo Zemek23-Jan-13 7:37
mvaPaulo Zemek23-Jan-13 7:37 
GeneralRe: Reversing time, without a flux capacitor Pin
Jonathan C Dickinson3-Feb-13 22:47
Jonathan C Dickinson3-Feb-13 22:47 

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.