Open Development/open source project-timedog [C # windowsapp]

Source: Internet
Author: User

Update@2005.8.19
Timedog latest v13

Http://www2.zzu.edu.cn/xb/timedog.exe
Download the source code here
Http://www2.zzu.edu.cn/xb/timedog_src.rar


====================
I have done a lot of ASP before. net web application development. However, I am not familiar with desktop application development and have never developed any software in this field. Now, I want to develop a web application together, use your spare time to develop your own applications. If you want to be a beginner in C # Or have mastered the development of C # Windows applications. net lovers communicate with me. QQ: 154222225.

The initial project requirements are as follows:

Name: timedog
Function: calculates the total running time of a computer from a certain time point. the software starts with the operating system and starts timing. When you shut down the operating system, the running time is stored to accumulate with the next running time. during the operating system running period, the user is not allowed to terminate the software process.

Developers:
# Caca (card) http://www.cnblogs.com/caca
# Frogman http://www.cnblogs.com/frogman/

The development progress is as follows:
1, the help in the csdn: http://community.csdn.net/Expert/topic/3797/3797941.xml? Temp =. 8971979.
2. self-starting solution:

Enable the program to run automatically at startup (modify the registry ?) :
Add your program to "HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run"

// Run automatically
Registrykey HKLM = registry. localmachine;
Registrykey run = HKLM. opensubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run", true );

If (run. getvalue ("lookout") = NULL)
{
String efilename = application. executablepath + ""; // contains the executable file name
Run. setvalue ("lookout", exefilename );
}
Run. Close ();
HKLM. Close ();

3. About. Net's hooks
Http://www.codeproject.com/csharp/GlobalSystemHook.asp

4. the auto-start and timing functions have been initially implemented. Considering the storage of trace data, it is temporarily stored directly in the registry. Private void form1_load (Object sender, system. eventargs E)
{
// Check whether the registry key has been set to auto start
Registrykey LM = registry. localmachine;
Registrykey run = LM. opensubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run", true );
If (run. getvalue ("timedog") = NULL)
{
String exefilename = application. startuppath + @ "\ timedog.exe ";
Run. setvalue ("timedog", exefilename );
}

// Set the registry key to store the system running time
If (run. getvalue ("timedogruntime") = NULL)
{
Run. setvalue ("timedogruntime", "00:00:00 ");
}

// Set the start time

Run. setvalue ("timedostarttime", datetime. Now. tostring ());

// System running time
MessageBox. Show ("the system is running:" + run. getvalue ("timedogruntime"). tostring ());
Run. Close ();
Lm. Close ();
}

Private void form1_closing (Object sender, system. componentmodel. canceleventargs E)
{
// When the user closes the window, the program running time is calculated and stored in the registry
Registrykey LM = registry. localmachine;
Registrykey run = LM. opensubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run", true );
Timespan lastall = (timespan) (convert. todatetime (run. getvalue ("timedogruntime"). timeofday); // obtain the last overall running time
Datetime timedostarttime = convert. todatetime (run. getvalue ("timedostarttime"). tostring (); // get the start time of this operation
Timespan Ts = datetime. Now-timedostarttime; // The current running time.
Timespan alltime = lastall + ts; // The overall time, including the current time.
If (run. getvalue ("timedogruntime") = NULL)
{
Run. setvalue ("timedogruntime", "0 ");
}
Else
Run. setvalue ("timedogruntime", alltime. tostring ());
}

5. Implement functions similar to QQ minimization. For details, refer:
C # Hide the window appllication as the taskbar icon when writing the minimal code.
6. Disable application. Private void form1_closing (Object sender, system. componentmodel. canceleventargs e) When you click the close button)
{
E. cancle = true;
}

7. Download the project source file

8. Windows Service Program Design
Use Visual C # To create a Windows Service Program
Use C # To create Windows Services)

9. It would be better to create a program with "no dead process". However, csdn users said that the process cannot be terminated by a base user, so someone suggested using process injection, these may only be implemented using assembly or C, and C # should not be implemented. Now we have developed a Windows service program version, a 22k program, and the knowledge is started in the service, when I stopped, I made some file read operations, but the memory (7.35 MB) I was not satisfied with. Where should I start with program optimization?
The Windows Service version provides source code download (for installation of the program, refer to the above two articles)

10. In Windows, users are prohibited from stopping services. When the user shuts down the computer, an event is triggered and the time is recorded. Therefore, the onshutdown () function should be rewritten instead of onstop () function protected override void onshutdown ()
{
Base. onshutdown ();
Writelog ("End @" + datetime. Now. tostring ());
Writelog ("============ ");
// Record the running time
Writetime ();
}

And write a timedogsee object for you to view the total running time of your computer.

11. put pictures of two programs
(: The program runs in the form of a later service, and the service cannot be stopped)

(: The process diagram of the program. How does 20 K program occupy so much memory ??? C # Is there any Optimization Method for the program "very memory-consuming? Is it because the background service program calls a lot of. Net Assembly, although the Code is just a few lines-the complexity of Microsoft's simplified program design .)

(: After the program runs for a period of time, the memory usage is greatly reduced)

(: Timedogsee, used to view the total running time of the system)

12. The following task is to build a distributed application. One of us installs this software to charge for timing, so we want to program through the network, it indicates the running time and detailed records that the user can send. The server can also control the running time of the client through the network-for example, resetting.

13. I remember reading a book about C # network programming in the summer of the last semester:
C # Network Programming
By Richard Blum ISBN: 0782141765
Sybex 2003 (647 pages)

At that time, I wrote a LAN chat program in the console. Now I plan to check it again.
It involves a network packet capture tool: Winpcap (Ethereal also calls it to capture packets), which can be downloaded here:
Http://netgroup-serv.polito.it/netgroup/tools.html

14. The software runs successfully, but you have to make improvements:
(1) Add scheduled computing results to prevent external power calls, or shut down processes (recorded) by users or systems ).
(2) the stored data is encrypted, and the path is more concealed.
(3) Deploy the software to facilitate installation, uninstall and update.

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.