Last active
May 3, 2016 15:49
-
-
Save mrtank/db049b37bae1bdf788f36693ebd6c0e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void BeginEndPairWithData() | |
{ | |
byte[] changingData = new byte[] { 0 }; | |
Action changeData = () => changingData = new byte[] { 1 }; | |
IAsyncResult res = changeData.BeginInvoke(changeData.EndInvoke, null); | |
res.AsyncWaitHandle.WaitOne(); | |
changingData.ShouldAllBeEquivalentTo((byte)1); | |
} | |
[TestMethod] | |
public void BeginEndPairWithDataInSeparateMethods() | |
{ | |
byte[] changingData = new byte[] { 0 }; | |
IAsyncResult res = BeginChange(ref changingData, EndChange); | |
res.AsyncWaitHandle.WaitOne(); | |
changingData.ShouldAllBeEquivalentTo((byte)1); | |
} | |
private void EndChange(IAsyncResult res) | |
{ | |
} | |
private IAsyncResult BeginChange(ref byte[] changingData, AsyncCallback callback) | |
{ | |
Action changeData = () => changingData = new byte[] { 1 }; // <-- problem here Can't change changingData in lambda | |
return changeData.BeginInvoke(callback, null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment