Solved

c# keep form open after exiting program

Posted on 2013-11-10
7
602 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
Comment Utility
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
Comment Utility
thanks James
regards
Pat
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:pclarke7
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now