Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 622
  • Last Modified:

c# keep form open after exiting program

I am new to c# and currently writing a barcoding application which reads through records grouped together by transaction name in a transaction file. Let say one such transaction called TRAN1 is made up of 30 transactions records sequenced 1 though to 30. In this transaction there are 4 required user inputs at sequence 2,10,20 & 25. A driver program (Forms application with form hidden) will read through each of the 30 records and at sequence 2,10,20 & 25 will call a User_Input form to take in the user input. The problem is that between sequence 2 & 10 there could be a delay of 5-10 seconds and the only form displayed is the User_Input. After each input is completed ,the form is closed when I return back to the Driver program making the whole process disjointed with delays between one input screen and the next input screen where nothing is displayed. Is there any way of keeping the User Input Screen Open when the Driver program is processing non Input sequences. I don't think a progress bar will work since most of the heavy listing is being done in the driver program which does not display a form. All suggestions welcome.
 
 regards
 Pat
0
pclarke7
Asked:
pclarke7
  • 3
  • 3
1 Solution
 
Jacques Bourgeois (James Burger)Commented:
I am not sure if I understand the question properly, because the text does not reflect the title.

Just answering the question in the title: No. When the program exits, it does not run anymore, so there is no way to leave the form on the screen. You might put a ProgressBar on the form to show the user that the application is waiting. Simply set its Style property to Marquee, and it will work continuously without your intervention.

Between inputs, simply put on a temporary form with a simple message telling something like "Preparing to process next input. One moment please...". When you are ready for the new input, open the form for that and hide the waiting message.
0
 
pclarke7Author Commented:
thanks James
regards
Pat
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Based only on your title, I agree with JamesBurger.

But you said: "A driver program (Forms application with form hidden)"

So you have all of this running in a WinForms application?

If yes, then it is possible to achieve what you want...we'd just need to see your code and refactor it accordingly.

At a high level...

Display your form with the input controls disabled, and the 'X' to close the form disabled.
Start your processing work in a background thread.
When input is required, enable the form and wait for proper input.
You can make the background thread wait for input using thread synchronization techniques such as a ManualResetEvent().
After input is received, signal the thread to continue and disable the form again.

The BackroundWorker() control would be useful, though not necessary.

Let me know if you want to attempt this.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
pclarke7Author Commented:
Thanks Idle Mind,
I'll go with James's suggestion as it is the simplier. However I am noticing flickering when the temp form is displayed with "Processing" message. Is there any way of minimizing this flicker.

regards
Pat
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
That really depends on how you designed the form, displayed the form, and whether you are updating it in anyway.

You could first try enabling the DoubleBuffered() property of that temp form and see if that helps.

Other than that we'd need to know a lot more information and possibly see code.
0
 
pclarke7Author Commented:
I have put together a simple example which illustrates how the screen flickers and the "processing please wait..." text does not appear on flickering Form3

Form 1 has a button called Start which when clicked will iterate from i from 0 to 99. When i is 10 or 20 an input screen (Form2) is called, otherwise a status screen (Form 3) is called. Form3 has a sleep(100) just to enable seeing the status screen. Appreciate any tips you can give regarding achieving a seemless transition between screens.

regards
Pat



 namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 100; i++)
            {
                //Display form as a modal dialog
                if (i == 10 || i == 20)
                {
                    this.Hide();
                    Form2 InputForm = new Form2();
                    InputForm.ShowDialog();
                }
                else
                {
                   
                    //Display form as a modal dialog
                    this.Hide();
                    Form3 StatusForm = new Form3();
                    StatusForm.ShowDialog();
                }
            }
            this.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}





namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}





namespace WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(100);
            this.Close();
        }
    }
}
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You are creating a new instance of  Form3 for every iteration.  Why not use the same instance over and over like this?
        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Application.DoEvents();
            Form3 StatusForm = new Form3();

            for (int i = 0; i < 100; i++)
            {
                //Display form as a modal dialog
                if (i == 10 || i == 20)
                {
                    StatusForm.Hide();
                    Application.DoEvents();

                    Form2 InputForm = new Form2();
                    InputForm.ShowDialog();

                    // ... other code? ...
                }
                else
                {
                    StatusForm.Show();
                    Application.DoEvents();

                    // ... other code? ...
                }
            }

            this.Show();
        }

Open in new window


You can get rid of the Sleep() call in Form3 then.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now