public virtual IAsyncResult BeginProcessRequest(RequestContext context, AsyncCallback callback, object state)
{
return this.process.BeginInvoke(**ref context**, callback, state);
}
public virtual RequestContext EndProcessRequest(IAsyncResult result)
{
RequestContext context = null;
this.process.EndInvoke(**ref context**, result);
return context;
}
The two methods above are causing some warnings in my project. I’m not sure I understand them. The warning is:
Argument is ‘ref’ while parameter is declared as ‘value’
and the location of the warning is the first parameter (context) in the Invoke calls. Does anyone see anything wrong with this or have some advice about the issue?
Those double asterisks are the cause of the warnings. I hit “bold” on the editor and it did that so I just went with it. The asterisks are not in my code.
Using
refwith delegates is a bad idea, IMO. (I’d say it’s normally a bad idea anyway, to be honest. Make your methods do one thing and have one result.)I didn’t think it would work at all – but apparently it does, so long as you supply the
refparameter when you callEndInvokeas well:The behaviour here is potentially confusing… I would avoid it if at all possible.
Most uses of
refare due to not understanding how parameter passing works in C#… is it possible that that’s the case here? Do you really need the first parameter to beref? Can you just make the return value of the delegate the new context instead?