Sleep in C++/CLI

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

Is there something similar for C++/CLI ?.

VOID WINAPI Sleep(DWORD dwMilliseconds);

I need to stop the execution between processes during a time.

Thanks in anticipation.
 
Is there something similar for C++/CLI ?.

The System::Threading::Thread class has a Sleep method.


Mattias
 
Simplified, I need to do this:

private: NameSpace::SpecialClass^ m_pSpecialClass;

private: System::Void button_Click(System::Object^ sender,
System::EventArgs^ e) {
if ( m_pSpecialClass->FunctionA() == false )
return;
Sleep(3000);
if ( m_pSpecialClass->FunctionB() == false )
return;
Sleep(3000);
if ( m_pSpecialClass->FunctionC() == false )
return;
Sleep(3000);

this->Close();
}

I need a stop between the functions and before to close de Form.
 
Hi Tomas,

Thanks for your feedback.

Yes, per your requirement, you may get it done by calling the static
Sleep() method of System::Threading::Thread class.

However, based on my my Winform programming experience, calling Sleep in
the GUI thread will prevent the message loop from doing it work, which
caused WM_PAINT, WM_SIZE and other messages not to be processed timely.
This will introduce an hang UI to the end user, which is considered to be
non user friendly.

If you care about this problem, then can you tell me why do you want to
delay/sleep 3 seconds between functions calling and before form closing?
Maybe you may put this function code in a second worker thread and let the
GUI thread responsible.

Anyway, if you think this is not a problem for your application, you may
just Sleep() method without any modification. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I need a stop between the functions and before to close de Form.

That's very unfriendly, and doesn't scale properly. You've
calculated how long a delay. What happens when someone runs your app
on a CPU twice as fast? Or half the speed? If you really do have code
that needs a fixed delay regardless of speed, why not just set a timer
(WM_TIMER in classic win32), and let the OS come back to you in a
while? That'll multitask better than a raw Sleep() call. If your
functions take a while, then use a thread and HEVENTs (win32 again,
not sure what the C# equivalent is) that signal when they're done?

Nathan Mates
 
I need close and open a file TXT that is used by another app.

If I do not put a delay between the processes I get an error message “files
is in useâ€.

Thanks for your help.
 
Hi Tomas,

Thank your for the further context information on this issue.

Yes, I see you used the Sleep(3000) to delay the opening to the in use
file. However, this may be not be best design, because other processes may
lock the in use file for more than 3000ms. This will still make the opening
fail. So I still would recommend you to place the code in a second UI
thread, this will free the entire UI thread for painting. Also, you may use
try...catch to swallow the file in use exception.

Anyway, if you think your current design is applicable, you may still use
it without change. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top