none
Releasing a start up form RRS feed

  • Question

  • Hello,

    Will try to explain the problem.
    My App, when it is in initial starting state (before Load) initializes different views and establishes DB connections..

    So it is busy for seconds..

    Following the Old School I've made just a spare short time living form with Always on Top, Centered at the screen plain, where I show some useful licence and Copyright information. Let me call it Banner Form (BF).

    When the initialing stack of object is ready, I just Close that Win and the user begins to do some work.

    What I have noticed now, when I wanted to add some animation on that BF using threading and the event recall from that thread with data is.. this BF is not yet ready to work until the general App Form is not finished with own start up.

    BF is animated only after the Main Form is Loaded, but until that - it is frozen.

    How to make that BF active and ready? Should I instead of MainForm Run the app with that BF, and then, on its Load - create and show the Main Form?

    Is there any other way to animate (release) BF before all main form objects are loaded and instantiated?


    "I = I + 1" .. Isn't it boolshit?

    Sunday, December 15, 2019 5:23 PM

Answers

  • Hello, thank you for your replies and help,

    I didn't know how it is called ))

    But I've done it my way:

            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    
                new Thread(delegate() {
                    StartUpScreen start = new StartUpScreen();
                    Application.DoEvents();
                    Application.Run(start);
                }).Start();
    
                Application.DoEvents();
                App app = new App();
    
                System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.RealTime;
                if (app.activated && app.Connected) { SayToPipe(true); Application.Run(app); }
                else SayToPipe(false);
    
            }
            static void SayToPipe(bool r) {
                byte OK = 0x00;
                byte ERROR = 0x01;
    
                using (NamedPipeServerStream pipeServer =
                new NamedPipeServerStream("SatestPipeOut", PipeDirection.Out)) {
                    pipeServer.WaitForConnection();
                    using (StreamWriter writer = new StreamWriter(pipeServer)) {
                        pipeServer.Write(new byte[] { r ? OK : ERROR }, 0, 1);
                        pipeServer.Flush();
                    }
                    pipeServer.Close();
                }
            }
    And the reverse side is:
        public partial class StartUpScreen : Form
        {
            public StartUpScreen()
            {
                InitializeComponent();
                new Thread(delegate() { ClientIn(new dCloser(Closer)); }).Start();
            }
            void Closer(bool reply){
                if (this.InvokeRequired) {
                    Invoke(new dCloser(Closer), reply);
                    return;
                }
                this.Close(); }
    
            void ClientIn(dCloser closer) {
                byte[] reply = new byte[1];
                using (NamedPipeClientStream client =
                new NamedPipeClientStream(".", "SatestPipeOut", PipeDirection.In)) {
                    client.Connect();
                    BinaryReader reader = new BinaryReader(client);
                    reader.Read(reply, 0, 1);
                    client.Close();
                }
                closer(Convert.ToBoolean(reply[0]));
                return;
            }
        }


    "I = I + 1" .. Isn't it boolshit?

    • Marked as answer by RobbKirk Tuesday, December 17, 2019 8:05 AM
    Monday, December 16, 2019 9:06 AM

All replies

  • The following is an outline for what you can do.

    Create a class or some classes for doing the initialization. Run the initialization in one or more threads, probably using the BackgroundWorker class. This question should have been put in the forum for the relevant UI (Windows Forms or WPF or whatever) because the details depend on the UI. If any of the initialization threads encounter an error then they can either create a form for that or use the banner form. You could even put progress messages in the banner form.

    As I said, details depend on the UI.



    Sam Hobbs
    SimpleSamples.Info

    Sunday, December 15, 2019 6:07 PM
  • Hi RobbKirk,

    Thank for posting here.

    According to your description, it seems that you are making a splash screen.

    If so,  please refer to the links below.

    How to build splash screen in windows forms application?

    How to keep Splash Screen displayed until main form has finished initializing.

    How to do Application Initialization while showing a SplashScreen.

    Hope this could be helpful.

    Best Regards, 

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 16, 2019 7:09 AM
  • Hello, thank you for your replies and help,

    I didn't know how it is called ))

    But I've done it my way:

            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    
                new Thread(delegate() {
                    StartUpScreen start = new StartUpScreen();
                    Application.DoEvents();
                    Application.Run(start);
                }).Start();
    
                Application.DoEvents();
                App app = new App();
    
                System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.RealTime;
                if (app.activated && app.Connected) { SayToPipe(true); Application.Run(app); }
                else SayToPipe(false);
    
            }
            static void SayToPipe(bool r) {
                byte OK = 0x00;
                byte ERROR = 0x01;
    
                using (NamedPipeServerStream pipeServer =
                new NamedPipeServerStream("SatestPipeOut", PipeDirection.Out)) {
                    pipeServer.WaitForConnection();
                    using (StreamWriter writer = new StreamWriter(pipeServer)) {
                        pipeServer.Write(new byte[] { r ? OK : ERROR }, 0, 1);
                        pipeServer.Flush();
                    }
                    pipeServer.Close();
                }
            }
    And the reverse side is:
        public partial class StartUpScreen : Form
        {
            public StartUpScreen()
            {
                InitializeComponent();
                new Thread(delegate() { ClientIn(new dCloser(Closer)); }).Start();
            }
            void Closer(bool reply){
                if (this.InvokeRequired) {
                    Invoke(new dCloser(Closer), reply);
                    return;
                }
                this.Close(); }
    
            void ClientIn(dCloser closer) {
                byte[] reply = new byte[1];
                using (NamedPipeClientStream client =
                new NamedPipeClientStream(".", "SatestPipeOut", PipeDirection.In)) {
                    client.Connect();
                    BinaryReader reader = new BinaryReader(client);
                    reader.Read(reply, 0, 1);
                    client.Close();
                }
                closer(Convert.ToBoolean(reply[0]));
                return;
            }
        }


    "I = I + 1" .. Isn't it boolshit?

    • Marked as answer by RobbKirk Tuesday, December 17, 2019 8:05 AM
    Monday, December 16, 2019 9:06 AM
  • You still do nt say what the UI is so I will assume it is Windows Forms.

    Do not use DoEvents. It was created for unmanaged VB but there is never a need for it in VB.Net. And I do not see any reason to use it here; I think you can totally remove it from both places in your code.

    The advantage of BackgroundWorker is that it has things like InvokeRequired are built into it. You can do everything (such as InvokeRequired) yourself if you want to.

    In the following code:

    new Thread(delegate() {
        StartUpScreen start = new StartUpScreen();
        Application.DoEvents();
        Application.Run(start);
        }).Start();

    As said, you do not need DoEvents and you do not need to put the message loop (Application.Run) in a separate thread.

    I do not know why you are using a pipe. If the only value sent and received in the pipe is a single boolean value then that is much easier to do than using a pipe.

    You seem to ignoring what I am saying so it seems futile for me to try to help.



    Sam Hobbs
    SimpleSamples.Info

    Monday, December 16, 2019 6:46 PM
  • You are very poor reader and too ambitious with your help.. sorry, it is not my fault.
    Thank you for your efforts to be helpful. it was me who voted up for your replies.

    You didn't understand the main - Application is not ready to do anything with any threading (including your favorite BW) until it's not in general Windows Messaging Loop.
    By placing it into Application.Run - you send your "ship to sail".

    Once it's released, it is able to fulfill all the menu of the day, including threading operations.


    "I = I + 1" .. Isn't it boolshit?





    • Edited by RobbKirk Tuesday, December 17, 2019 3:50 PM
    Tuesday, December 17, 2019 8:04 AM