0

I have searched in many threads of stackoverflow, Code Project, C# Corner and many other forums. My Question is cloned. But i can't any satisfactory solution. I want to show a wait form that will appear when there is some sort of background work . Back ground work may include opening a form , filling Grid View etc batching and processing commands.

private void newVendorBtn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

            if (newVendor==null||newVendor.Text=="")
            {

              SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false);
                newVendor = new newVendorForm();
                newVendor.MdiParent = this;
                for (int i = 0; i <= 100; i++)
                {
                    SplashScreenManager.Default.SetWaitFormDescription(i.ToString() + "%");
                    Thread.Sleep(5);


                }
                SplashScreenManager.CloseForm(true);

                    newVendor.Show();
            }
            else if(CheckOpened(newVendor.Text))
            {
                newVendor.WindowState = FormWindowState.Normal;
                newVendor.Show();
                newVendor.Focus(); 
            }
            //newvendorBool = addPanel(ref newVendorDP, newVendor, ref newvendorBool, "New Vendor");

        }

Now here is question , how wait can form should be appear for dynamic time dependent upon machine processing. If application is run on Latest fast machine (i.e. i7, i5 ,others etc) wait form should appear fewer time where as if is on Pentium 3 ,4 It should appear for long time until processing is complete. I am Developing c# Winforms application.

Allah Rakha
  • 65
  • 2
  • 11
  • What have you tried? there are a number of google results for showing something while something is being processed.... your question is remarkably vague.. – BugFinder Aug 01 '15 at 18:51
  • @BugFinder , as i mentioned forums , i find solution that uses to put your thread in to sleep for a fixed time. Problem is that , if machine is slower and time span is passed than application will not respond. To avoid i must wait for time that should be calculated dynamically. – Allah Rakha Aug 01 '15 at 18:58
  • Then you need to re-read what this site is for, we do not do your work for you, we help you fix it when it doesn't work - you've shown no work. – BugFinder Aug 01 '15 at 18:59
  • @BugFinder , Forum also contains solutions of many problems & discussions. If you can't provide than does't make any difference. Many of other may know the solution. – Allah Rakha Aug 01 '15 at 19:12
  • @BugFinder , question is updated , and i have shown the code. Code is working . But i have clearly mentioned that it must be dependent upon machine. Not in some specific time period that is statically assigned. – Allah Rakha Aug 01 '15 at 19:17
  • OK, but theres no context, you're kinda going about it back to front.. You don't show a window for a time, you tell a window to show when you start and go when you're done.. it doesn't seem like theres any research behind that concept at all – BugFinder Aug 01 '15 at 19:32
  • Your `for loop` counting to 100 is unnecessary and is just adding extra time to the process. You're not going to be able to calculate how long you have to wait. Instead you should: 1) Show the wait screen 2) start the task 3) task is processing 4) task ends 5) close the wait screen. If you want to update a status on the wait screen with some %, then in #3 you send an update to your wait screen. – Chase Rocker Aug 01 '15 at 19:37
  • @ChaseRocker according to my point of view , before starting loop , i have created instance of my object and my actual process is on creating instance. In loop i m showing a wait screen and status is updated on count down . – Allah Rakha Aug 01 '15 at 19:50
  • Calling me "babe" will not make me code it for you. This place does NOT code stuff for you. – BugFinder Aug 01 '15 at 19:54
  • @BugFinder :-D , you mind it. O.k apologize you. – Allah Rakha Aug 01 '15 at 19:57
  • @A.RShaib yes, I see what you're doing...and BugFinder and I are telling you that you're doing it wrong. Your "count down" code is unnecessary and is just adding more time to the process. Read my Steps #1 - 5 above again. That's what you should be doing. To apply that concept to your specific example you should: Remove your `For Loop`...you don't need it. Move the `SplashScreenManager.CloseForm(true);` line below `newVendor.Show();` and you're done. And if your newVendor form has some tasks that it does during loading which takes time, you send update % msgs to your SplashScreenManager form – Chase Rocker Aug 01 '15 at 20:06
  • @ChaseRocker , Have you noted when Visual Studio Loads a solution and show a loading dialog message...???? You might note that it does not take a fix time slice . Have you any idea about this one...??? How doe's it works..??? – Allah Rakha Aug 04 '15 at 18:06
  • @BugFinder read my above comment. – Allah Rakha Aug 04 '15 at 18:07
  • Yes, Visual Studio shows the 'Loading Solution' form and in the background, it runs thru it's loading process. That's what I described above and that's exactly how you should do it. Which part of this concept is still confusing to you? – Chase Rocker Aug 04 '15 at 18:27
  • @ChaseRocker yeah little bit confusing for me. would you like to illustrate with some example via code . It would be pleasure for me . With my best regards , i would like to thanks for helping me. – Allah Rakha Aug 05 '15 at 17:42
  • see my answer below for an example of this concept – Chase Rocker Aug 05 '15 at 19:39

1 Answers1

1

Here's pseudo-code to show you an example of this concept. You can modify it for C#:

newVendorBtn_ItemClick{

                SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false);
                newVendor = new newVendorForm();
                newVendor.MdiParent = this;

                //This triggers the newVendor_Load
                newVendor.Show(); 

                //newVendor is done loading, close the splash screen
                SplashScreenManager.CloseForm(true);
}

newVendor_Load{
     //newVendor Form does some tasks when it's first loaded
     //these tasks will take different times to complete on different computers
     //as each is completed, the splash screen is updated.

     performLoadingTask1();
     SplashScreenManager.Default.SetWaitFormDescription("20% complete");

     performLoadingTask2(); 
     SplashScreenManager.Default.SetWaitFormDescription("40% complete");

     performLoadingTask3(); 
     SplashScreenManager.Default.SetWaitFormDescription("60% complete");

     performLoadingTask4(); 
     SplashScreenManager.Default.SetWaitFormDescription("80% complete");

     performLoadingTask5(); 
     SplashScreenManager.Default.SetWaitFormDescription("100% complete");

}
Chase Rocker
  • 1,908
  • 2
  • 13
  • 14