Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Delay code execution

After searching hours and hours and debugging and whatnot seems like i just cant find a solution to so simple problem... what i need is something like this

for(int i=0; i<100; i++)
{
wait here 2-3 seconds
string result = doSomeGUIworkHere();

if(result == desiredResult)
{
break;
}
}

I tried Thread.Sleep, timer with elapsed event, task delay with async await... But to no awail. If i use thread.sleep it just blocks thread and wont do doSomeGUIworkHere();
If i use timer then it just fires doSomeGUIworkHere(); 100 times.

Please help.
Use a thread? charlimit

[warn]
(Sep 14, 2017 12:56 PM)SIM-2071734 Wrote:  Use a thread? *charlimit*
Any code sample? :)
Why would you have to wait? Maybe theres a better approach to what youre trying to achieve than to wait.
https://msdn.microsoft.com/en-us/library....110).aspx
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
Do not use a thread! That'd be a huge waste of processor time. Just use await or a timer (which is actually the same, await Task.Delay as mentioned above might be the best solution). Can you show us your not working code with async/await?
[Image: signature.png]
async void Dank()
{
for(int i=0; i<100; i++)
{
await Task.Delay(2000);
string result = doSomeGUIworkHere();

if(result == desiredResult)
{
break;
}
}
}
should work i guess
Thank you guys! I have found your suggestions very helpful and i have found solution so thanks all!! :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by ClumsyOct 11, 2022 05:31 AM 0 190 Oct 11, 2022 05:31 AM
Last Post: Clumsy
[.NET] by ChaosComputerDudeJan 21, 2020 04:23 AM 0 127 Jan 21, 2020 04:23 AM
Last Post: ChaosComputerDude
[Shell] by Minerva5Nov 20, 2018 08:04 AM 8 433 Nov 20, 2018 08:04 AM
Last Post: CyberStrike