❔ Some bug i guess

Code that works
Task.Run(() => Static_class_name.START(param1, param2, param3));
Task.Run(() => Static_class_name.START(param1, param2, param3));
*inside the static class Static_class_name *
public static Task START(decimal param1, decimal param2, int param3)
{}
public static Task START(decimal param1, decimal param2, int param3)
{}
But i want to send more paramters like extra 3 string params which makes the function not want to run Code that does not work
Task.Run(() => Keyboard_and_Mouse.START(param1, param2, param3, param4, param5, param6));
Task.Run(() => Keyboard_and_Mouse.START(param1, param2, param3, param4, param5, param6));
*inside the static class Static_class_name *
public static Task START(decimal param1, decimal param2, int param3, string param4, string param5, string param6)
{}
public static Task START(decimal param1, decimal param2, int param3, string param4, string param5, string param6)
{}
A small modification in the code for Task.Run() that does not work
var t1 = param4;
var t2 = param5;
var t3 = param6;
Task.Run(() => Keyboard_and_Mouse.START(param1, param2, param3, t1, t2, t3));
var t1 = param4;
var t2 = param5;
var t3 = param6;
Task.Run(() => Keyboard_and_Mouse.START(param1, param2, param3, t1, t2, t3));
Now this will work and then function would run anyone got any suggestions? I will be open to live stream if needed for a better understanding. It does not make sense that when i put the values param4, 5, 6 directly to the function call, it does not run but when i put it in another variable and then put the variable in the function parameters, it works. (NOTE : all the parameters are coming from windows form application) param1 -> itemA_numericupdown.value param2 -> itemB_numericupdown.value param3 -> itemB_numericupdown.DecimalPlaces param4 -> itemC_combobox.Text param5 -> itemD_combobox.Text param6 -> itemE_combobox.Text
20 Replies
ACiDCA7
ACiDCA72y ago
im not too keen on winforms, but it might have something to do with that you are trying to access a UIelement from another thread when you are creating a new variable it will copy the string still in the uithread. and since you are now working without a uielements it works but thats just my 2 cents
infernus8349
infernus8349OP2y ago
but param1,2,3 are also from windows forms i am not sure why this is happening but i am going to try to put the parameters 4,5,6 as .ToString() so that it will actually copy let me see how that goes nope, it does not work
ACiDCA7
ACiDCA72y ago
just to make sure, you meant
Task.Run(() => Keyboard_and_Mouse.START(itemA_numericupdown.value, itemB_numericupdown, itemB_numericupdown.DecimalPlaces, itemC_combobox.Text, itemD_combobox.Text, itemE_combobox.Text));
Task.Run(() => Keyboard_and_Mouse.START(itemA_numericupdown.value, itemB_numericupdown, itemB_numericupdown.DecimalPlaces, itemC_combobox.Text, itemD_combobox.Text, itemE_combobox.Text));
this doesnt work but
Task.Run(() => Keyboard_and_Mouse.START(param1, param2, param3, t1, t2, t3));
Task.Run(() => Keyboard_and_Mouse.START(param1, param2, param3, t1, t2, t3));
wherever param1/2/3 are coming from, does
infernus8349
infernus8349OP2y ago
yea yeah in the question i named param1, param2 was becuase it would be more cleaner in acutal code, its not exactly param1, 2, 3 those are actaul values direclty from windows form only the last 3 are making the problem
ACiDCA7
ACiDCA72y ago
hmm ok
infernus8349
infernus8349OP2y ago
so i put them in variables t1,2,3 and then sent those 3 variables during function call that works i still dont know exactly why it does not work if sent directly to function call than putting it in a variable i am hoping someone can help me in this
ACiDCA7
ACiDCA72y ago
btw what exactly do you meant by "Code that does not work" do you get a runtimeexception?
infernus8349
infernus8349OP2y ago
no, after the Task.Run() executes, the function i mentioned inside Task.Run() just does not run no error, just does not run now that you have mentioned, let me try putting it in try catch statement hold on
ACiDCA7
ACiDCA72y ago
can you put a await in fronbt of Keyboard_and_Mouse
infernus8349
infernus8349OP2y ago
like Task.Run( () => await Keyboar
ACiDCA7
ACiDCA72y ago
basicly
Task.Run(() => await Keyboard_and_Mouse.START(param1, param2, param3, t1, t2, t3));
Task.Run(() => await Keyboard_and_Mouse.START(param1, param2, param3, t1, t2, t3));
infernus8349
infernus8349OP2y ago
like this? ok hold on cannot use it as the fucntion that uses Task.Run() is not async Start_function() contains the Task.Run() and its not async also this Start_function() is being run by a function which run during the buttonclick of windows form i just tried putting the Task.Run() in try catch, it never got caught some hidden problem is happening which makes the function not want to run if last 3 parameters are sent directly than putting it in some variables and passing it over
ACiDCA7
ACiDCA72y ago
yea there are some shenanigans regarding not awaited tasks
infernus8349
infernus8349OP2y ago
harold wish it alreayd showed me some error let me try to send 4 parameters, i never tried that, hold on
ACiDCA7
ACiDCA72y ago
there is a explanation for it but i currently dont have the mental capacity to explain it in detail..xD
infernus8349
infernus8349OP2y ago
doesn't work xD i think this got something to do with where the data is coming from i think its something related to combobox.Text
ACiDCA7
ACiDCA72y ago
anyway. did you try to not make it a anonymous method and then create a breakpoint in it
infernus8349
infernus8349OP2y ago
nope, let me try OK, IT WORKS!!!!!!!!!!! looks like Task.Run() is on drugs
MODiX
MODiX2y ago
ACiDCA7#8219
yea there are some shenanigans regarding not awaited tasks
Quoted by
<@!267749179470774272> from #Some bug i guess (click here)
React with ❌ to remove this embed.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server