Highlighted
Respected Contributor.
Respected Contributor.
340 views

Creating a 'Sleep' function in Windows Form

Jump to solution

Is there a way to display a form for about 5 seconds and then return to the program? What I am basically trying to do is to display a background form and then display another form on top of it (I do not wish to hide the background form until the user triggers an event on the second form). I therefore want to invoke the second from within my background form without closing or hiding the background form.

 

I did this once with a Visual Basic form as follows:

System.Threading.Thread.CurrentThread.Sleep(5000)

 

But I do not know if there is anything remotely similar in Managed COBOL.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Creating a 'Sleep' function in Windows Form

Jump to solution

You could place the Sleep function in a different event handler like, Activate or Shown perhaps?

You could also place it after the Form.Show method invocation in the original form code:

Something like:

           declare newform = new Form2
           invoke newform::Show
           invoke type System.Threading.Thread::Sleep(5000).
           invoke newform::Close

The Sleep function will make the UI unresponsive and may not be the best choice for this functionality. 

Somebody else may have a better solution for you here like perhaps setting a timer, etc.?

View solution in original post

0 Likes
4 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Creating a 'Sleep' function in Windows Form

Jump to solution

Most .NET Framework classes and methods are available in Visual COBOL although the syntax may be a bit different.

You can invoke the Sleep method:

       invoke type System.Threading.Thread::Sleep(5000)

or if you have VC 5.0 await can be used as follows to accomplish the same basic functionality.

       invoke await type System.Threading.Tasks.Task::Delay(5000)

If you use await then you need to mark the current method as async or async-void.

       Example:
            method-id buttonRead_Click final private async-void.

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Re: Creating a 'Sleep' function in Windows Form

Jump to solution

This semi- works. What I have is the following:

 

method-id TPS0010Form_Load final private.
procedure division using by value sender as object e as type System.EventArgs.

set txtLOGON-SIGN-ON::BackColor to type Color::White.
set txtLOGON-SIGN-ON::ForeColor to type Color::Black.
invoke type System.Threading.Thread::Sleep(5000).


end method.

 

What this code does is that it waits for about 5 seconds and then displays the screen. I would like to do the opposite if it is possible. I want to display the screen and then return to the program automatically after 5 seconds (almost like a splash screen).

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Creating a 'Sleep' function in Windows Form

Jump to solution

You could place the Sleep function in a different event handler like, Activate or Shown perhaps?

You could also place it after the Form.Show method invocation in the original form code:

Something like:

           declare newform = new Form2
           invoke newform::Show
           invoke type System.Threading.Thread::Sleep(5000).
           invoke newform::Close

The Sleep function will make the UI unresponsive and may not be the best choice for this functionality. 

Somebody else may have a better solution for you here like perhaps setting a timer, etc.?

View solution in original post

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Re: Creating a 'Sleep' function in Windows Form

Jump to solution

This worked for what I want to achieve, thank you! But if anyone else has ideas on setting the screen to time off, please let me know. I am trying to see if there is a better way.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.