Pass By Reference Not Allowed In UI Threading Of Windows Forms In C#
The code below does not allow pass by reference to be used in UI threading
particularly method Invoker.
The solution is to store the method parameter in another variable as shown below:
Cheers!
particularly method Invoker.
private void ShowPassMeta(ref int passedSound) { if (lblPassSoundex.InvokeRequired) { lblPassSoundex.Invoke((MethodInvoker)delegate { ShowPass(ref passedSound); }); } else { lblPassSoundex.Text = (++passedSound).ToString(); } }
private void ShowPassMeta(ref int passedSound) { var passedSound1 = passedSound; if (lblPassSoundex.InvokeRequired) { lblPassSoundex.Invoke((MethodInvoker)delegate { ShowPassMeta(ref passedSound1); }); } else { lblPassSoundex.Text = (++passedSound1).ToString(); } }
Comments
Post a Comment