Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

c# keep form open after exiting program

Posted on 2013-11-10
7
607 Views
Last Modified: 2013-11-12
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
Comment
Question by:pclarke7
  • 3
  • 3
7 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39637286
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
 

Author Closing Comment

by:pclarke7
ID: 39637418
thanks James
regards
Pat
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39637450
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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

Author Comment

by:pclarke7
ID: 39640070
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39640392
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
 

Author Comment

by:pclarke7
ID: 39642923
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39643257
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question