Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c# keep form open after exiting program

Posted on 2013-11-10
7
Medium Priority
?
620 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
[X]
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
  • 3
  • 3
7 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1500 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 86

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 86

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 86

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

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!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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