This makes IIS and its recycling tangle

Source: Internet
Author: User

I thought it was a great pleasure to end the project. I did not expect that the automatic reminder was difficult at the end, and I still couldn't find the reason.

 

I didn't encounter this problem when I was studying global at school, so I don't know where I am, and I didn't find any problems by checking the code. The scheduled task is to execute the task at PM and PM every day. Unfortunately, humans are not as good as computers.

 

Not executed on the first day .. Restart IIS and run the command. Well, we can only wait until the next day to test the execution. Go to work the next day .. Not executed.

 

The analysis at the time was that the thread might sleep (Why didn't I realize the concept of sleep ). Short cut interval. To check whether the problem is caused by code, execute the task once every minute. The Code does throw an exception. I did not find it during my own check. Okay. Continue to execute. Everything is OK.

Change to 1 hour, wait for one hour, and find some global configuration problems, but no result. I also failed to execute the task, but I didn't give it the permission. I don't think it has much to do with the permission, so I just tried to add it to IIS.

 

Of course, the answer is yes. There is no change to the result, so it is okay to test the machine for 1 hour. Okay. It should be okay. Submit it and release it again. Once in the first hour. I think the problem was found. The tester told me that the data was deleted and tested again. The result is not executed when it is executed for the second time.

 

At that time, I was puzzled because a lightweight timer was used to avoid poor thread control. But I didn't expect it to be so unreliable. Once executed, it stops. A little pitfall.

At that time, I thought it was actually gone (I still didn't realize that the error was going through the second time), so I should define timer as public. I see how you disappear. By the way, I am adding a static object to you.

Okay. The test will take 1 minute. No problem

Test for 10 minutes.

Test for 1 hour. It disappears...

It disappears locally and does not understand the reason for its dissipation. Because it is not executed at all. Where is the error?

The tangle of one sleep leads to insomnia. The next day there is no spirit and a headache. The first thing to do is to find a problem. But unfortunately, I have no thoughts. I also told my group about this problem. They suggested that I add logs. I have added the log to execute it again and again. According to the log feedback, he suddenly disappears. There is no indication. Specifically, after the application_start event is executed, the timer delegation time is not executed.

It can only be tested in a stupid way. The execution time is 1 minute. Everything works. Normal in 10 minutes. 30 minutes. Take a break at noon and have a three kingdoms attack. I watched the results in the afternoon and did not run it. I did not expect that this broken problem had plagued me all morning. At this time, some people in the group said it may have been recycled by IIS. Search Baidu for IIS Global to recycle the three keywords. The answer is found.

But I am not sure if this answer is correct and targeted at my program, so I wrote a log in application_end. If it is entered here, record it. The program is still half an hour. The results are obvious. The program is started successfully. The program will end in 21 minutes.

21 minutes. What can this do. I changed my program to 15 minutes for execution.

Run once. Wait for the second time until the program ends in 21 minutes. Everything is dispose.

Reading Baidu's article, I mean,"ASP. NET applications are closed from time to time. The interval is about 1 ~ Once every 5 hours."In fact, this result is suitable for me, because the interval is 21 minutes. That is to say, the automatic shutdown time of his application pool is not controllable. Now there are several solutions.

1. Modify the garbage collection time of IIS, And the application_start after the collection starts the event. Http://blog.csdn.net/orain/article/details/4589984)

2. Modify the runtime interval (it has been passed because it is recycled no matter how it is run)

3. Keep your website in the accessible status. In application_start.

4. Write Windows Services

 

Consider writing Windows Services again and again. Because that article also said that it is best for such long-time automatic programs to write Windows Services. There are too many uncontrollable factors in IIS.

 

I started to write Windows Services because the previous website code was encapsulated in the class library. I wanted to flip the dynamic class library and reference the call method. Unexpectedly. An error occurred while referencing. I mean I am in poor spirits. Collapsed. The three views collapsed. But be calm. According to the warning information, Baidu once found that the default framework set of the original Windows Service and Asp.net application is different. But there are two types on net framework4.0 (my computer can't do it)

Adjusting the framework set is successful when everything is generated. However, it is added to the service and stops running .. Stop automatically. All right, you can write the shanzhai log. When the BLL layer references the method, the exception is not thrown but ended directly. How fragile are you with Windows Services.

This is a headache. Copy the class library and reference it. The result is still incorrect. Well, the three-tier architecture is not suitable for you. One layer. East and West. Or not. What is an error. The leaders showed me a windows call company component project that was previously written by the company. It turns out that there is only one sentence in APP. config.Providername = "system. Data. sqlclient"(Driver) but this sentence is not used in the Asp.net project. It seems that I have been doing Web projects for a long time.

Service up. But the database has not changed. Well, I can't help it because I know that Windows Service debugging must be based on services or windbg, but the latter has never been used. It is not easy to find the installation package, which is a kind of Windows SDK.

If it runs successfully, debug it ..

Who has changed the database... Why is the field required ....

The operation is successful. The mind left a shadow ..

I have written several methods and it's time to get off work. The last test was not performed. Test it on Monday.

Finally, I will summarize the following points.

At the beginning of the design project, we must consider the issue of recycling, because in the. Net World recycling does not require human control (does IIS fall within the. NET scope ?) Therefore, the memory is not considered.

Second, you must consider whether your automatic program is a kind of long-time automatic program for web projects. We need to consider IIS recycling. The last and most important point is to design the log, which is the system log, because this log can help future maintenance personnel to perform scientific and rapid maintenance, reduce unnecessary time expenditure for developers and maintenance personnel. If logs are taken into account at the beginning, the problem exposure may take longer for some solutions.

When using different programs, you may find that the DLL usage is incorrect. Check whether the framework set of the two programs is the same (right-click the project class library property to see it)

Because the framework set is incorrectly used by different ides. In fact, this problem should be mostly used between different ide versions of DLL, which happened to me by chance.

Finally, it is about global. Its compilation is dynamic compilation, which should be compiled only when IIS is running. Global compiled DLL does not exist in any DLL (I personally think it has not passed the Il test. DLL, but I did not find it. Later I tried to write the code according to the web site, and put the post-CS code into his page. This is because the front page is not compiled during net compilation, but all Cs files are packaged.

There is also the need to improve your awareness and code quality. Correct mentality. At first, I realized that it would dissipate, but I did not find the reason, and I did not find the reason for the second disappearance. Only when someone else finally knows that his disappearance is related to garbage collection.

And I am more aware that Asp.net is not omnipotent. Many things still require the use of CS programs for more reliable implementation. After all, IIS is not developed by our group of people. Of course, you can try to develop an IIS ..

It is important to have an experienced team. If any problem occurs, consult with others. I was born by myself.

 

Of course, if something is wrong, please give pointers. After all, new users still need to hone their skills !~

I am also very shameless to publish to the home page .... Hey.

GROUP: 59557329

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.