Click here to Skip to main content
16,010,553 members
Home / Discussions / C#
   

C#

 
QuestionProcess Enumeration loop Pin
Haydn01223-Jul-09 4:06
Haydn01223-Jul-09 4:06 
Hi, i am very new to C#, im trying to create a file that enumerates the processes constantly, checking whether a process which is written in a txt file is running, and if so, it prints it in a .ini file, So far everythings working fine. But it only works when i open the file while the desired process is already running, thus the program has to be re-opened everytime for it to update. is there a way to make this code loop? or a mor efficiant way to get the desired effect?

Heres my code
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
    class Program
    {
        [STAThread]
        [DllImport("kernel32.dll", EntryPoint = "WritePrivateProfileString")]
        private static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName);
        static void Main(string[] args)
        {
            string line;
            System.IO.StreamReader file = new System.IO.StreamReader("X:\\file.txt");
            while ((line = file.ReadLine()) != null)
            {
                Process[] procs;
                procs = Process.GetProcessesByName(line);
                foreach (Process p in procs)
                {
                    WritePrivateProfileString("Main", "Current Process", line, ("X:\\config.ini"));
                }
            }
            file.Close();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

AnswerRe: Process Enumeration loop Pin
DoctorMick23-Jul-09 5:23
DoctorMick23-Jul-09 5:23 
GeneralRe: Process Enumeration loop [modified] Pin
Haydn01223-Jul-09 5:29
Haydn01223-Jul-09 5:29 
QuestionDataTable.Select() PRoblem Pin
jonhbt23-Jul-09 3:12
jonhbt23-Jul-09 3:12 
AnswerRe: DataTable.Select() PRoblem PinPopular
Tom Deketelaere23-Jul-09 3:19
professionalTom Deketelaere23-Jul-09 3:19 
GeneralRe: DataTable.Select() PRoblem Pin
jonhbt23-Jul-09 3:25
jonhbt23-Jul-09 3:25 
GeneralRe: DataTable.Select() PRoblem Pin
jonhbt23-Jul-09 3:27
jonhbt23-Jul-09 3:27 
GeneralRe: DataTable.Select() PRoblem Pin
Tom Deketelaere23-Jul-09 3:40
professionalTom Deketelaere23-Jul-09 3:40 
GeneralRe: DataTable.Select() PRoblem Pin
jonhbt23-Jul-09 3:51
jonhbt23-Jul-09 3:51 
GeneralRe: DataTable.Select() PRoblem Pin
Tom Deketelaere23-Jul-09 4:03
professionalTom Deketelaere23-Jul-09 4:03 
GeneralRe: DataTable.Select() PRoblem Pin
jonhbt23-Jul-09 4:20
jonhbt23-Jul-09 4:20 
GeneralRe: DataTable.Select() PRoblem Pin
Tom Deketelaere23-Jul-09 4:29
professionalTom Deketelaere23-Jul-09 4:29 
GeneralRe: DataTable.Select() PRoblem Pin
jonhbt23-Jul-09 4:43
jonhbt23-Jul-09 4:43 
GeneralRe: DataTable.Select() PRoblem Pin
Tom Deketelaere23-Jul-09 5:01
professionalTom Deketelaere23-Jul-09 5:01 
AnswerRe: DataTable.Select() PRoblem Pin
jonhbt23-Jul-09 5:27
jonhbt23-Jul-09 5:27 
GeneralRe: DataTable.Select() PRoblem Pin
MumbleB23-Jul-09 3:36
MumbleB23-Jul-09 3:36 
GeneralRe: DataTable.Select() PRoblem Pin
jonhbt23-Jul-09 3:43
jonhbt23-Jul-09 3:43 
QuestionBorder Less Window Mouse Left click Pin
satsumatable23-Jul-09 2:45
satsumatable23-Jul-09 2:45 
AnswerRe: Border Less Window Mouse Left click Pin
shlomtzi23-Jul-09 2:52
shlomtzi23-Jul-09 2:52 
GeneralRe: Border Less Window Mouse Left click Pin
satsumatable23-Jul-09 2:57
satsumatable23-Jul-09 2:57 
GeneralRe: Border Less Window Mouse Left click Pin
shlomtzi23-Jul-09 3:04
shlomtzi23-Jul-09 3:04 
AnswerRe: Border Less Window Mouse Left click Pin
Henry Minute23-Jul-09 3:25
Henry Minute23-Jul-09 3:25 
GeneralRe: Border Less Window Mouse Left click Pin
satsumatable23-Jul-09 5:13
satsumatable23-Jul-09 5:13 
GeneralRe: Border Less Window Mouse Left click Pin
Henry Minute23-Jul-09 6:08
Henry Minute23-Jul-09 6:08 
Questionneed suggestion how to move object on screen in run time Pin
shlomtzi23-Jul-09 2:39
shlomtzi23-Jul-09 2:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.