CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Posts
    17

    Need help My program takes 30% of my i7 2600k processor

    i wonder why my processor takes 30% of my processor
    i even use i7 2600k

    when i tried at my pc at work it takes almost 100%
    but the pc didnt lag at all..

    i use a timer - inverval 100
    and use 1 background woker

    any idea??

  2. #2
    Join Date
    Feb 2012
    Location
    Strasbourg, France
    Posts
    116

    Re: Need help My program takes 30% of my i7 2600k processor

    A bit of your code would be appreciated as we can't figure what it's doing

  3. #3
    Join Date
    Mar 2012
    Posts
    17

    Re: Need help My program takes 30% of my i7 2600k processor

    i can't really give the full code because its like 1500++ line.
    so i dont even think it will help..

    so i figure and take what they do.
    some of them still a function.. so

    ill explain a little bit

    add(parameter) = add to list
    getFiles(parameter) = recursive for taking folder directory based on what user drag and drop

    so basicly this timer doing anything else. but it never take like this..

    after i implement the background worker here the problem comes..
    i just wonder do they really gone if i dispose it?
    after all i went to give List to a Background worker so every files added to my list .
    will be added and not wait for all files be read.

    why i use multiple background worker is simple as like this
    after i add. i wanted my files to be added to the datagridview.
    so i create a background worker named thread..
    he is the one and only one background worker still running even the data already added all.

    for the background worker is like this

    Code:
    private void bg_RunWorkerCompleted(object sender,RunWorkerCompletedEventArgs e) 
            {
                BackgroundWorker temp = sender as BackgroundWorker;
                temp.Dispose();
                bg.Remove(temp);
            }
            private void bg_DoWork(object sender,DoWorkEventArgs e) 
            {
                Add_list al = (Add_list)e.Argument;
                String[] directoryName = al.data;
    
                foreach (string data in directoryName)
                {
                    if (data.LastIndexOf(".") >= 0
                        && (data.Substring(data.LastIndexOf(".")).ToLower().Equals(".mp3")
                            || data.Substring(data.LastIndexOf(".")).ToLower().Equals(".flac"))
                        )
                    {
                        add(data, al.header);
                    }
                    else
                    {
                        getFiles(data, al.header);
                    }
                }
            }
            private void thread_DoWork(object sender,DoWorkEventArgs e) 
            {
    
            }
            private void thread_RunWorkerCompleted(object sender ,RunWorkerCompletedEventArgs e) 
            {
                if (add_lastIndex < x.Count) 
                {
                    addToListBasedOnHeader(x[add_lastIndex]);
                    add_lastIndex++;
                }
                thread.RunWorkerAsync();
            }
            private void read_bg_DoWork(object sender, DoWorkEventArgs e)
            {
                String[] ListName = (String[])e.Argument;
                try
                {
                    for (int i = 0; i < ListName.Length; i++)
                    {
                        StreamReader sr = new StreamReader(Application.StartupPath + "/playlist/" + ListName[i] + ".dmpp");
                        String list_Error = "";
                        List<String> temp = new List<string>();
                        while (!sr.EndOfStream)
                        {
    
                            String path = sr.ReadLine();
                            if (!path.Equals(""))
                            {
    
                                //This Slower Because CHECKING ALL DATA WHEN READ
                                String File = path;
                                if (System.IO.File.Exists(File))
                                {
                                    //add(File,ListName.Items[i].ToString());
                                    temp.Add(File);
                                }
                                else list_Error += File + Environment.NewLine;
    
                                // this not check before adding
                                //add(path, ListName.Items[i].ToString());
    
                            }
                        }
                        if (!list_Error.Equals("")) MessageBox.Show(list_Error + "All List Above Was Not Found..");
                        sr.Close();
                        Add_list al = new Add_list();
                        al.data = temp.ToArray();
                        al.header = ListName[i];
                        addBG();
                        bg[bg.Count - 1].RunWorkerAsync(al);
                    }
    
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
            private void read_bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
                BackgroundWorker temp = sender as BackgroundWorker;
                temp.Dispose();
                bg.Remove(temp);
            }
    and for the timer

    Code:
    private void value_Tick(object sender, EventArgs e)
            {
                autosetcolor();
                //label3.Text = "" + bg.Count;
                //label3.Text = x.Count + "-" + list[ListName.SelectedIndex].Rows.Count;
                if (WindowState == FormWindowState.Minimized && minimized == 0)
                {
                    if (option.mtst.Checked == true)
                    {
                        GoToTray();
                    }
                }
    
                if (status_play == 1 )
                {
                    //seek_bar.Maximum = (int)wmp.controls.currentItem.duration;
                    try
                    {
                        if (status_down == 0) seek_bar.Value = (int)wmp.controls.currentPosition;
                        DurationText.Text = "";
                        if ((int)wmp.controls.currentPosition / 60 < 10) DurationText.Text += "0";
                        DurationText.Text += (int)wmp.controls.currentPosition / 60;
                        DurationText.Text += ":";
                        if ((int)wmp.controls.currentPosition &#37; 60 < 10) DurationText.Text += "0";
                        DurationText.Text += (int)wmp.controls.currentPosition % 60;
                        DurationText.Text += "/";
                        if ((int)wmp.controls.currentItem.duration / 60 < 10) DurationText.Text += "0";
                        DurationText.Text += (int)wmp.controls.currentItem.duration / 60;
                        DurationText.Text += ":";
                        if ((int)wmp.controls.currentItem.duration % 60 < 10) DurationText.Text += "0";
                        DurationText.Text += (int)wmp.controls.currentItem.duration % 60;
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message); }
                }
            }

  4. #4
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: Need help My program takes 30% of my i7 2600k processor

    If your system is reporting 25% processor utilitzation on a quad-core system (for example, an i7) then it (likely) means some process is fully utilizing one (of four) cores. This probably occurs because you're calling a subroutine very 100 ms that takes longer than 100 ms to complete (thus, constant utilization).
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured