I stand for a βsmallβ syntax problem and cannot figure out how to write what I want to.
I have the following method:
public void DoSomeMagic(string foo, ref string bar) {
Now I would like to unload this code inside Task.Run, I would usually write the following:
public async void Button_Click(object sender, EventArgs args) { string foo = "Hello Foo"; string bar = "Hello Bar"; await Task.Run(() => DoSomeMagic(foo, ref bar)); }
This does not compile, telling me: "It is not possible to use the" ref "or" out "parameter in the anonymous method panel"
So I thought, why even does () =>, since I just call the method, and I could reduce it to this:
Task.Run(DoSomeMagic(foo, ref bar));
This again does not compile, telling me: the Run (void) method cannot be resolved, the candidates: Run (Action) and Run (Func)
So again, the problem with Visual Studio is my team.
And changed the code to this:
Task.Run((Action)DoSomeMagic(foo, ref bar));
Doesnβt compile again, telling me: cannot express an expression like 'void' to type βActionβ,
Well, this is starting to get complicated ...
I, than tried, instead of returning void, I just try int and throw it in Func giving me an error: cannot express an expression like "int" to type "Func"
I saw that it would come, but I thought, let's try:
So, I tried the following approach:
public Action CallDoSomeMagic(string foo, ref string bar) {
But this again gives me the message "Cannot use the" ref "or" out "parameter" bar "inside the body of the anonymous method"
As my headache grows with every attempt, I thought you guys can help me. Is it possible?