asynchronous - C# Tuple not returning value -
it's first time using tuple's might doing wrong or missed small. used have repetitive code :
if (!b1fturn) { if (b1turn) { fixcall(b1status, ref b1call, ref b1raise, 1); fixcall(b1status, ref b1call, ref b1raise, 2); rules(2, 3, "bot 1", ref b1type, ref b1power, b1fturn, b1status); autoclosemsb.show("bot 1 turn", "turns", thinktime); ai(2, 3, ref bot1chips, ref b1turn, ref b1fturn, b1status, b1power, b1type); turncount++; b1turn = false; b2turn = true; } } if (b1fturn && !b1folded) { bools.removeat(1); bools.insert(1, null); maxleft--; b1folded = true; } if (b1fturn || !b1turn) { await checkraise(1, 1); b2turn = true; }
and had copied , pasted 5 times decided put in method , paste method 5 times instead. started doing realized need await methods went async task<some input>
need values few booleans , int's .2 options either return or use ref/out. ref/out not allowed in async methods anyway return left. things needed few different types of data returned needed (it tuple). created 1 method using tuple :
async task<tuple<bool, bool, bool>> rotating(bool tempturn, bool permaturn, bool folded, string name, label status, int botcall, int botraise, int start, int end, int current, bool next, double power, double type, int chips) { if (!permaturn) { if (tempturn) { fixcall(status, ref botcall, ref botraise, current); fixcall(status, ref botcall, ref botraise, start); rules(start, end, name, ref type, ref power, permaturn,status); autoclosemsb.show(name + " turn", "turns", thinktime); ai(start, end, ref chips, ref tempturn, ref permaturn, status, power, type); turncount++; tempturn = false; next = true; } } if (permaturn && !folded) { bools.removeat(current); bools.insert(current, null); maxleft--; folded = true; } if (permaturn || !tempturn) { await checkraise(current, current); next = true; } return new tuple<bool, bool, bool>(tempturn, permaturn, next); }
as can see says return bool,bool,bool , after values need get. didn't work out next didn't got it's value changed if put breakpoint on return
line false next turns true, once quit's method it's default false . same goes other 2 booleans. why ? doing wrong how fix this.
- p.s needed return few int's mentioned earlier removed them sake of simplicity.
edited after conversation in chat: can await async function give tuple, use this:
var r = await test (x, y); // x,y example, test returns tuple can access r.item1 , r.item2
Comments
Post a Comment