Vs2005 of the Simple Logging tool--6. Start

Source: Internet
Author: User
Tags data structures

Let's talk about the system startup.
When it comes to startup, it reminds me of another depressing place: The WinForm program is too slow to start, compared to other development tools such as Delphi. Start a WinForm program, it may be a long time before the system really entered. In this process, it is also a good idea if you can start to organize and react and let people see what the program is doing.
Open the MyLog3 solution, and in the MYLOG3 project you can find a window tfrmconver that looks like this:


  
This interface wants it to do two things:
The first is to start, display some startup information, and second, you can use the "about" command to display it, you can view the software at any time some relevant information.
The startup information is displayed in Label1, which is implemented by the following function:



         Public   void SetInfo ( int Step , string InfoText)
... {
Label1. Text = step . ToString () + ". " + infotext;
Application.doevents ();
System.Threading.Thread.Sleep (a);
}


The construction of this class is defined as private, because some initialization properties are the same each time the interface is used, so the code that generates the object is encapsulated in the function Showcover:



         Private Tfrmcover ()
... {
InitializeComponent ();
}

Public   Static tfrmcover Showcover ( BOOL ShowDialog)
... {
Tfrmcover form= NewTfrmcover ();
Form.label1.Text= "";
Form. Topmost= true;

Form._isstart= !ShowDialog;

if(ShowDialog)
Form. ShowDialog ();
Else
Form. Show ();

returnform;
}

The Form.ShowDialog () and Form.show () in. NET are two more interesting functions. The former causes the invoked thread to enter a "blocking" state, and only after the window of the ShowDialog () is closed can the following code be executed, while the latter has no effect.
In MyLog3, Tfrmcover has two places to use, one of which is primarily used to display startup information, and the other is to display it through commands. Obviously, the former state cannot use ShowDialog () and should use Show (), and the latter is best to use ShowDialog ()-which is also a habit.
As a result, a parameter, bool ShowDialog, is added to the Showcover to determine which way the generated Tfrmcover object is displayed.
Form. topmost = True This code refers to displaying the window as the topmost window.
The Tfrmcover also defines a bool variable _isstart, which is used to control the automatic shutdown of the window-but it is not the point to say here.

With the interface to start displaying information, you can start the system step-by-step, and the startup code is written in the main function of the program class for each WinForm application:



         Static   void Main ( string [] args)
... {
//
        }

When the 4th file type is registered, a command entry is written to the registry that causes the full path of the ML3 file to be started as a command-line argument whenever a ML3 file is run MyLog3.exe. To get the path to this ML3 file, you need to do a little "surgery" on main, as shown in the preceding code, adding an argument:



string [] args

This way, you can get the command-line arguments for the incoming program by args the string array.

The first two sentences of the main function code are available in every WinForm program, without any change:



Application.enablevisualstyles ();
Application.setcompatibletextrenderingdefault ( false );

Then we're going to generate the Tfrmcover object to display the startup information:



tfrmcover Form = Tfrmcover.showcover ( false );

Start the system below:

1. Increase (or update) the association of ML3 files with MyLog3.exe applications by calling functions in the class tsysregeist.



form. SetInfo ( 1 ,  " Check registration Information " );
Tsysregeist.addregeist ();

2. Check the command-line arguments, which can be divided into three different scenarios:
The first is that there are no command-line arguments, the application exits, and the second case is a command-line argument, but the value equals "DelReg," where the ML3 file type needs to be removed from the system by the Tsysregeist class; The last situation needs to check whether the file specified by the parameter exists or exits without exists, continue to the next step.



form. SetInfo ( 2 ,  " Check command line arguments " );
Check Parameters #regionCheck Parameters
stringFilePath= NULL;
if((args!= NULL) &&(args. Length> 0))
...{
FilePath = args[0];
}

if(FilePath== NULL)
...{
return;
}
if(FilePath== "DelReg")
...{
Form. SetInfo (3, " Uninstall registration information ");
Tsysregeist.delregeist ();
return;
}
if (!System.IO.File.Exists (FilePath))
...{
return;
}
#endregion

3. If the program does not exit, perform the third step to check the data structure:



form. SetInfo ( 3 ,  " Checking data Structures " );
Check Data #region Check Data
Tsysdata sysdata = new tsysdata (FilePath);
#endregion

4. To build the main window:



form. SetInfo ( 4 ,  " initializing the main window " );
Tfrmmain MainForm =   New Tfrmmain (Sysdata.dataset, filePath);

5. Initialize the data in the main window:



form. SetInfo ( 5 ,  " Initializing Data " );
Mainform.init ();


Here is a suggestion that the main window's data initialization process should not be placed in the main window's Load event, but placed in a custom initialization function.

Finally, release the message prompt window and enter the application:



form. Dispose ();
Application.Run (mainform);

The next article, log type management class Tstyle implementation.
ie.2008-04-08.



<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.