Timing Out a Windows Form in Managed COBOL

I posed a similar question a few months back but I did not get the responds that I was looking. Is there a way to implement a timeout feature in WinForm? What I am trying to accomplish is to display a form for about 5 seconds and then have the form close by itself without user intervention so that it may continue running the program. I read an articles at the following address: https://social.msdn.microsoft.com/Forums/vstudio/en-US/719cb7c9-afad-4d88-968d-2be7b4da0e39/how-to-implement-a-timeout-feature-in-windows-forms?forum=winforms

But it pertains to C#. Any ideas on how to achieve this in managed COBOL? I tried doing the following in the ‘Activate’ event of my form:


       method-id TPS0021J_Activated final private.

       procedure division using by value sender as object e as type System.EventArgs.


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

           invoke self::Close()


This block of code gets executed whenever the form is activated. This works if I ‘Step Into’ the program but it doesn’t work if I run it without any break points. If I can get this block of code to work when I run the program without breakpoints then it will solve my problem.

  • What is the task that you are actually trying to accomplish? Is this a type of splash screen that you wish to display? If so then then the article here is probably more useful.

    The article you pointed to actually implements a timer that checks for user inactivity. If the mouse or keyboard remains untouched for 5 seconds it will redisplay the login screen.

    Is this what you are trying to do?

  • All I want to do is to display information for the user to see briefly and then return to the program without user intervention.
  • I suppose a way around this problem is to check for inactivity or if the form is idle. The link I submitted gives an example using c#. I found another link that gives information about an Idle event handler: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.application.idle?view=netframework-4.8. But again, it is in C#. Can any of these events be done in managed COBOL?

  • Verified Answer

    Just about anything you can do in C# you can also do in COBOL as they are both .NET languages that can directly use the classes of the .NET Framework.

    There is a section in the documentation that shows a comparison of .NET COBOL with C# and VB.NET. Take a look here.

    That being said, I can get this timed form to work by implementing a Timer in the form to be displayed. If you want the displayed form to always stay on top then set its TopMost property to True and set the TopMost property of the other form to false. This does not keep the user from interacting with the underlying form however. Implement the Timer in the second form by dragging a Timer control onto its surface and then generate the Timer_Tick event handler as shown below.

    method-id Form2_Load final private. procedure division using by value sender as object e as type System.EventArgs. set timer1::Interval = 5000 invoke timer1::Start end method. method-id Timer1_Tick final private. procedure division using by value sender as object e as type System.EventArgs. invoke self::Close end method.


  • Thank you for your solution. I realize that both C# and managed COBOL use the .net framework. However, the commands are not the same and hence why I'm always asking for the managed COBOL version of the C# solutions. It is of very little use to me to see the documentation on C# if I do not know what the equivalent commands are in managed COBOL. And it is often the case that I spend hours trying to replicate a C# solution because I do not know the commands in Manged COBOL. Anyway, I solved this problem as follows: 

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

    invoke self::Show.

    set textBox1::SelectionStart to 0.
    invoke textBox1::Focus.
    set textBox2::SelectionStart to 0.
    invoke textBox2::Focus.
    invoke type System.Threading.Thread::Sleep(2000)
    invoke self::Close().

    end method.


    The "invoke self::Show" was splashing the form but with blank text boxes (the information that I was populating my text boxes with was not being shown).  I then realized that by setting the SelectionStart and the Focus properties of my text boxes ,  it displayed the information in my text boxes. I then used a sleep command on the form and then closed the form. So this achieves what I wanted to do as it displays the form with information I want the user to see for about 5 seconds and then closes without the user's need to intervene. I will try your suggestion on another form to see if it works better. Thanks for your help!!