C
C#17mo ago
infernus8349

❔ 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
ACiDCA717mo 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
infernus834917mo 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
ACiDCA717mo 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
infernus834917mo 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
ACiDCA717mo ago
hmm ok
infernus8349
infernus834917mo 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
ACiDCA717mo ago
btw what exactly do you meant by "Code that does not work" do you get a runtimeexception?
infernus8349
infernus834917mo 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
ACiDCA717mo ago
can you put a await in fronbt of Keyboard_and_Mouse
infernus8349
infernus834917mo ago
like Task.Run( () => await Keyboar
ACiDCA7
ACiDCA717mo 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
infernus834917mo 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
ACiDCA717mo ago
yea there are some shenanigans regarding not awaited tasks
infernus8349
infernus834917mo ago
harold wish it alreayd showed me some error let me try to send 4 parameters, i never tried that, hold on
ACiDCA7
ACiDCA717mo ago
there is a explanation for it but i currently dont have the mental capacity to explain it in detail..xD
infernus8349
infernus834917mo 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
ACiDCA717mo ago
anyway. did you try to not make it a anonymous method and then create a breakpoint in it
infernus8349
infernus834917mo ago
nope, let me try OK, IT WORKS!!!!!!!!!!! looks like Task.Run() is on drugs
MODiX
MODiX17mo 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
Accord17mo 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
More Posts
❔ Visual Studio not producing templates?Hey everyone, I'm attempting to teach myself C# via this website " https://www.w3schools.com/cs/cs_g❔ Confusing ClientWebSocket.ReceiveAsync() behaviorPicture the following class: ```cs private ClientWebSocket _ws = new(); private Memory<byte> _buffe❔ Better way to do this random password generation programThis program generates a random password then removes duplicates and excludes some chars. I need sug✅ Validation Error with Discord.Addons.HostingI'm trying to use Discord.Addons.Hosting, but it throws an OptionsValidationException . My main look❔ Need help with zooming a user control.I want to zoom a control based on the current cursor location. I have attached two files: In Form2✅ stateful versus stateless methods?Could someone please give me a simple example of these 2 methods as I don't really get what they do❔ IL weaving with Mono.Cecil in Unity isn't affecting Unity's assembly.Hello, I wrote a simple program that finds methods decorated with an [Rpc] attributes, which works a❔ can't access anonymous object properties by namein this https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/anonymous-types the first❔ Which should I use for windows application net framework 4.8 or net 5.0I currently need to use a tool called WinAPIDriver it supports currently pre release 5.0 net core an❔ Streams BinaryData Base64 differencesMay I ask the difference between BinaryData, Base64, Stream? Stream is an abstraction for stream lik