[WPF] the app. G. CS file cannot be modified, and the problem is automatically restored after modification. Solution

Source: Internet
Author: User
Tags ukey

When I first came into contact with WPF, the company required to use WPF to develop a project. The standalone version [microfinance loan information statistics system], and the ukey verification was added when I was asked to log on later, so I began to find the project portal method, rewrite the main entry method, compile and report an error, saying that the main method already exists, and check the information online. WPF ApplicationProgramIt will be created for us at the time of creation Main Function and call Application Instance Run Function to start Application Process. This Main The function is app. G. CS The automatically generated Main Function. The app. G. CS file is located in the \ OBJ \ x86 \ debug or release folder (based on your output mode ). Automatic Main The function is as follows:

///   <Summary>
/// Application entry point.
///   </Summary>
[System. stathreadattribute ()]
[System. Diagnostics. debuggernonusercodeattribute ()]
Public   Static   Void Main (){
Pettysecuredloanms. app =   New Pettysecuredloanms. app ();
App. initializecomponent ();
App. Run ();
}

I am trying to add my ukey authentication logic in this main method

 

 

1 ///   <Summary>
2 /// Application entry point.
3 ///   </Summary>
4 [System. stathreadattribute ()]
5 [System. Diagnostics. debuggernonusercodeattribute ()]
6 Public   Static   Void Main (){
7 If ( ! Webac. webac_customersystemvalidate ()) // Whether to insert ukey and the ukey is used by the System
8 {
9 Checkukwhenlogin newwindow =   New Checkukwhenlogin ();
10 Newwindow. showdialog ();
11 Return ;
12 }
13 Pettysecuredloanms. app =   New Pettysecuredloanms. app ();
14 App. initializecomponent ();
15 App. Run ();
16 }

Running successful

I thought it was successful, but when I regenerate the application, a message will pop up asking me to talk about the app. g. CS file recovery, I chose not to recover, although this is troublesome, it is also implemented, but found that when the project is closed and re-opened, the app. g. the CS file is regenerated.

Solution 1:

This is becauseApp. XAMLFile property generation(Build action).

Change the default applicationdefinition to page.

Then implement the main method in the app. XAML. CS file.

 

  ///   <Summary>
/// Interaction logic for app. XAML
///   </Summary>
Public   Partial   Class APP: Application
{
[Stathread]
Static   Void Main ( String [] ARGs)
{
If ( ! Webac. webac_customersystemvalidate ())
{
Checkukwhenlogin newwindow =   New Checkukwhenlogin ();
Newwindow. showdialog ();
Return ;
}
Pettysecuredloanms. app =   New Pettysecuredloanms. app ();
App. initializecomponent ();
App. Run ();
}
}

 

Rebuild successful.

Let's briefly describeVariousDifferences between buid actions

 

*None: This file is neither compiled nor output. For example, readme.txt is a document file in the project.

*Compile: Participate in compilation and output. MainlyCodeFile.

*Content: Does not participate in compilation, but is output.

*Embedded Resource: This file is embedded into the DLL or EXE generated by the main project. Mainly resource files.

*Applicationdefinition: Similar to page, but only used for the launch page of Silverlight (App. XAML by default ).

*Page: All usercontrol/page/childwindow XAML in silverligh belong to "page" build. Other build actions cannot connect code behind files with XAML files.

*Codeanalysisdictionary: Custom codeanalysis dictionary. (Reference http://blogs.msdn.com/ B /codeanalysis/archive/2007/08/20/new-for-visual-studio-2008-custom-dictionaries.aspx)

*Resource: Embeds the file in a shared (by all files in the Assembly with similar setting) assembly manifest resource named appname. G. Resources

*Splashscreen: Welcome Page of Silverlight.

*Designdata: Sample data types will be created as faux types. Use this build action when the sample data types are not creatable or have read-only properties that you want to defined sample data values.

*Designdatawithdesigntimecreatabletypes: Sample data types will be created using the types defined in the sample data file. Use this build action when the sample data types are creatable using their default empty constructor.

*Entitydeploy: Applicable to the Entity Framework.

 

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.