Results 1 to 2 of 2

Thread: [1.0/1.1] Ensure I am always running from the correct folder [C# 2002]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Question [1.0/1.1] Ensure I am always running from the correct folder [C# 2002]

    When a user launches my application the first thing I want to do is check to ensure I am in the correct folder, if so just continue, but if not I need to copy myself to that folder, start myself in that folder, and close the current instance of myself... All this needs to happen without the user "seeing" anything like window flashing, etc... So far I have the current code:

    Code:
    if (Application.ExecutablePath.ToUpper() != sWorkPath)
    {
    	if (File.Exists(sWorkPath))
    		File.Delete(sWorkPath);
    	File.Copy(Application.ExecutablePath, sWorkPath, true);
                        
    	Process pProcess = new System.Diagnostics.Process();
    	pProcess.StartInfo.FileName = sWorkPath;
    	pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    	pProcess.Start();
    
    	Application.Exit();
    }
    So this should:
    - Check to ensure I am running in the WORK folder
    - If not then copy myself to WORK
    - Start a process of myself in WORK
    - Close myself
    All without any flashing - so I run this as the first step of the form load (frmMain_Load) as any point before that Application.Exit() (also tried
    this.Close();) doesn't seem to work at all...
    But sadly this still causes some "flashing" to occur as I assume this is because I am running this code in the FORM_LOAD event so the form is being drawn and then exited ... I need to ensure no flashing occurs ...

    Questions are simple - is this the right approach to solve my problem and if not can you recommend something better?
    Is this the right place to run this code (begining of the Form Load) or could you offer a better, possibly earlier, location where this can/should be run to avoid this flashing issue I am having...
    What is the best way to ensure I end this current running process? this.Close();? Application.Exit();?

    Any help would be greatly appreciated... if there are other better ways to do this also... any suggestions would help (I just thought this up as a solution)
    Thanks,

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: [1.0/1.1] Ensure I am always running from the correct folder [C# 2002]

    Put your code in the static "Main" method of the project..It's the first entry to your application , here you can pass even params before your form is shown.

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