"An investment in knowledge always pays the best interest."Benjamin Franklin

Introduction

In this article, I would like to discuss problems the Splash \ Login Forms creating. I often stumble on the questions of the novice programmers about the Splash \ Login Forms on the forums. In my opinion, the answers on these questions often don't give a comprehensive information. So I decided to write the article. It fully describes these problems and solutions.

At first, I would like to discuss a question - What causes these problems to arise? In my opinion it is connected with an insufficient information or a fuzzy concept about the Windows architecture and Windows processes when we start executing program in the Windows systems. Here's the main problem. So let's resolve it. I am not going to retell a big good books about Windows, there is no point. I only want to let you have the opportunity to know about the creation of the instance program in Windows. That will give you an understanding of how to create the Splash \ Login Forms.

What is a Process?

First, we'll discuss a definition of "process in Windows". The Process - it is a copy of the executable program, and it consists of two components:

An object of the kernel, through which the operating system manages the process. It keeps the static information about the process.

An address space that contains executable code and data of the process.

The process itself does nothing, i.e., it is inert. To make it do something, it should have at least one thread. The thread is responsible for the execution of code in the address space of the process. Therefore, when the process is starting, the operating system automatically creates the main thread, which in turn can generate other threads. In addition, if we want our application to respond to the mouse moving, the button clicking, and so on, we have to create a message loop in the thread. So we have some structure: process - thread - a message loop. If we want to close the program, we need to close the main message loop. It happens when you close the main form or doing method Application.Exit(), as well as the method ExitThread() in the main thread.

How Do I Do It?

All discussed above, Visual Studio creates automatically, when we choose to create a project template with Windows Forms Application. Armed with this knowledge, take a look at the code, which we all certainly have repeatedly seen:

When you call a method Application.Run (new Form1 ()), we create a new thread that creates a message loop, and an object of class Form and shows it. Let us carefully consider this method. This method is overloaded, and may have the following options:

We are not interested in the first overloaded method in the context of this article, unless, of course, you decide to create something in the unsafe code, the third method we have already discussed. But the second is what we will be particularly interesting in. This creates the object class ApplicationContext, which is responsible for creating the thread and the standard cycle of message. Now everything is pretty simple - we must create a descendant class LoginTestContext of class ApplicationContext, which we will create a logic with application forms:

Creating the Splash Form

That's it! The Splash form is displayed when we need it and at the time that we need. Here, in place of slumber thread, you can do something really necessary, such as loading any resources, while showing progress bar or some other kind of information.

Creating the Login Form

Now we'll discuss the problem of the Login form establishing. The Login form follows after the Splash form. The Login form in any case should be closed. When it is closing itself, we must determine whether the login is made in the application:

The search function of the user name in the list IsExistNikName (string name) is implemented using lambda expression UserData => UserData.Nikname == NikName. In this case, the explanation the entity lambda expressions is too simple. For more information about the lambda expression, see this link.

Conclusion

That is all I wanted to tell you on this topic. I hope I succeeded in revealing the topic of this article fully. The implementation of the classes registration form and Login form, I think, will not cause any difficulty in understanding, but if you have any questions please write, I'll answer everyone.

If you remove the "UserData.xml" file you can add a new user and the main application is fully accessible by this new user.
You can also add a new user if you do not know one or his password, and then login with this user account.
Only to inform the new readers of this article.

You are right but it is a simple example. You can improve it. Store this data as binary and make hash code for this file. So you check hash for this file with the loading binary file if it is changed - hashes will be not equal. It will be enough for the better security

Thank you for the good code provided.
One suggestion: each time when you open the splash form, the back form will appear suddenly then the backgroud picture showes. I thought it is not so good. how to get rid of this?

This code can be right. But has some problems with:
1. support relogin without reloading an application
2. support background loading the Main form with the Login Form or/and Splash.
In the next article I will show how this works in my code.
3. security

Broken English? Are you kidding me? Give him credit for being able to program in a language not his own and for contibuting a good article. I am willing to bet that the documentation and manuals he uses are not in his native language and he probably understands them much better than I do. Good job Vladimir!!!!!!

I will not argue. It makes no sense - any of the technologies of cryptography has its pluses and minuses. But in this case - MD5 enough. You could apply to the class System.Security and chose the cryptographic protection, which you need.