Click here to Skip to main content
15,914,419 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem in window Service Pin
Justin Perez11-Jan-08 2:29
Justin Perez11-Jan-08 2:29 
Questionhow to log keystroke through windows Service? Pin
Somnath Sen11-Jan-08 0:52
Somnath Sen11-Jan-08 0:52 
AnswerRe: how to log keystroke through windows Service? Pin
Dave Kreskowiak11-Jan-08 1:41
mveDave Kreskowiak11-Jan-08 1:41 
GeneralRe: how to log keystroke through windows Service? Pin
Somnath Sen11-Jan-08 1:59
Somnath Sen11-Jan-08 1:59 
GeneralRe: how to log keystroke through windows Service? Pin
Justin Perez11-Jan-08 2:31
Justin Perez11-Jan-08 2:31 
GeneralRe: how to log keystroke through windows Service? Pin
Pete O'Hanlon11-Jan-08 3:28
mvePete O'Hanlon11-Jan-08 3:28 
GeneralRe: how to log keystroke through windows Service? Pin
Dave Kreskowiak11-Jan-08 4:01
mveDave Kreskowiak11-Jan-08 4:01 
Questionstack issue Pin
Goncalo Oliveira11-Jan-08 0:29
Goncalo Oliveira11-Jan-08 0:29 
Consider the following code...

<br />
<br />
string text;<br />
foreach ( something )<br />
{<br />
   if ( something )<br />
   {<br />
      text = "closing";<br />
      someForm.FormClosing += delegate( object sender, FormClosingEventArgs e )<br />
         {<br />
            MessageBox.Show( text );<br />
         };<br />
   }<br />
<br />
   if ( something_else )<br />
   {<br />
      text = "closed";<br />
      someForm.FormClosed += delegate( object sender, FormClosedEventArgs e )<br />
         {<br />
            MessageBox.Show( text );<br />
         };<br />
   }<br />
}<br />


The foreach will have a something, and then a something_else, in this order. So, what will happen here, is that both events will trigger a MessageBox displaying "closed" text. To fix this, I passed the string text inside the foreach, and the issue isn't an issue anymore.

Now... can anyone explain me why does this happen? The delegate uses the reference instead of the value?

Gonçalo A.

GeneralRe: stack issue Pin
Dave Kreskowiak11-Jan-08 4:07
mveDave Kreskowiak11-Jan-08 4:07 
GeneralRe: stack issue Pin
Goncalo Oliveira11-Jan-08 4:21
Goncalo Oliveira11-Jan-08 4:21 
GeneralRe: stack issue Pin
Dave Kreskowiak11-Jan-08 4:38
mveDave Kreskowiak11-Jan-08 4:38 
GeneralRe: stack issue Pin
Goncalo Oliveira11-Jan-08 4:46
Goncalo Oliveira11-Jan-08 4:46 
GeneralRe: stack issue Pin
Dave Kreskowiak11-Jan-08 6:28
mveDave Kreskowiak11-Jan-08 6:28 
GeneralRe: stack issue Pin
Goncalo Oliveira11-Jan-08 6:39
Goncalo Oliveira11-Jan-08 6:39 
GeneralRe: stack issue Pin
Dave Kreskowiak11-Jan-08 12:22
mveDave Kreskowiak11-Jan-08 12:22 
GeneralRe: stack issue Pin
Goncalo Oliveira11-Jan-08 12:29
Goncalo Oliveira11-Jan-08 12:29 
GeneralRe: stack issue Pin
Dave Kreskowiak12-Jan-08 6:53
mveDave Kreskowiak12-Jan-08 6:53 
GeneralRe: stack issue Pin
Dave Kreskowiak12-Jan-08 6:53
mveDave Kreskowiak12-Jan-08 6:53 
GeneralRe: stack issue Pin
Goncalo Oliveira12-Jan-08 6:58
Goncalo Oliveira12-Jan-08 6:58 
GeneralRe: stack issue Pin
Dave Kreskowiak14-Jan-08 6:06
mveDave Kreskowiak14-Jan-08 6:06 
GeneralRe: stack issue Pin
Goncalo Oliveira14-Jan-08 6:27
Goncalo Oliveira14-Jan-08 6:27 
GeneralRe: stack issue Pin
Dave Kreskowiak14-Jan-08 12:01
mveDave Kreskowiak14-Jan-08 12:01 
GeneralRe: stack issue Pin
Goncalo Oliveira14-Jan-08 12:58
Goncalo Oliveira14-Jan-08 12:58 
GeneralRe: stack issue Pin
Skippums11-Jan-08 4:49
Skippums11-Jan-08 4:49 
GeneralRe: stack issue Pin
Goncalo Oliveira11-Jan-08 4:54
Goncalo Oliveira11-Jan-08 4:54 

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.