c# - Is there a way I can inline a function to an Action delegate and referenced it at the same time? -
Is there any way that I can inline the delegated work instead of separating it into another function?
Original code:
Private order of de-attachment_fileoak (Object Sender, CancelEventErgus E) {System.Threading.ThreadPool.QueueUserWorkItem ((O) => Attach Do ()); } Attach zero () // I want to inline this function on file aak event {if (it is invisible) {this.Invoke (new action); } Other {// attach it daily here}}
I wanted to do it like this (no need to create a separate function):
Private Zero Off Attachment_fileAak (Object Sender, CancelEventErguesE) {Action Attached = Representative {if (This. InvoiceEreer) {// But here it is compiled with "Unassigned Local Variable" Use '' 'This. (New Action (Enclosed));} Else {// Regular Activity Marriage}}}; System.Threading.ThreadPool.QueueUserWorkItem ((o) => enclosed ())}}
I think this will work:
personal reasons fordAttachment_FileOk (object sender, CancelEventArgs e) {action attaching = ft; attachach = delegate {if (this .InvokeRequired) {// Since we are empty, we will be fine, and the automatic // clearer created by the compiler will ensure that we need it when we need it. This.Invoke (new action ));} Else {// Regular activity Attached}}}; System.Threading.ThreadPool.QueueUserWorkItem ((o) = & gt; enclosed ()); }
Assign a value to the 'enclosed' (zero function) before you declare the method of grant. I think it is a little easier to understand the former.
Comments
Post a Comment