none
C# - Registry - Too much CPU. Where is problem? ;/ 50-70kCPU

    Question

  • Welcome!
    I wrote a program that adds up and runs with autostart. But I have a problem. The program takes a lot of memory ... From 54-70k CPU. Where it can be a problem?

    The code generally works, added to the startup under the given name, etc., but it takes a lot of memory. I write code that will perform the same operation as this, but it will take very little memory? The Delphi is something that about 2,000 CPUs, and here from 54.000 to 70.000; /

    Here is my code:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using Microsoft.Win32;
    
    namespace WindowsFormsApplication1
    {
     public partial class Form1 : Form
     {
     public Form1()
     {
     InitializeComponent();
     }
    
     public static void startup()
     {
    
     string source = Application.ExecutablePath.ToString();
     string destination = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
     destination = System.IO.Path.Combine(destination, "Programik.exe");
     try
     {
     System.IO.File.Copy(source, destination, false);
     source = destination;
     }
     catch
     {
     }
    
     try
     {
     RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
    
     if (registryKey.GetValue("NowyProgram") == null)
     {
     registryKey.SetValue("NowyProgram", destination);
     }
    
     registryKey.Close();
     }
     catch
     {
     }
     }
    
     private void Form1_Load(object sender, EventArgs e)
     {
     startup();
     }
     }
    }
    

    Thursday, December 30, 2010 2:19 AM

All replies

  • Hi,

    Based on your description, please consult your question to C# forum. I'll help you moving your thread to appropriate forum.

    Best Regards,

    Larcolais


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 31, 2010 3:44 AM
  • Hi xDamianx,

    Welcome to MSDN forums.

    I am not clear about your question from your description, the previous code take a lot of memory? and which code take very little memory?

    Would you please clarify your post, thanks for understanding.

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 05, 2011 1:57 AM