0

I have essentially two programs:

  1. main.exe
  2. update.exe

Update creates a flag file (update.inprogress) so that main cannot run while the update is in progress.

If main opens and that file exists, it immediately exits to prevent a program in use conflict.

I'm only having one issue. If the update is in process, the main program closes without and reason when they try to go in. I need to tell them the program is updating to keep them from calling us that the world has come to an end...

My question is, how can I issue a message that the update is in progress without tying up the main.exe? If I issue it from main.exe, then it will be in use and cannot be updated.

I was thinking of opening up notepad and putting a message in there but that just seems like a bad way of doing it.

I could also create another exe that only displays this message, but, if I have to update it, it will be in use too.. kind of defeats my purpose.

Anyone have a better idea?


Clarification:

This is a peer-to-peer network. The update could be run on workstation XYZ and someone could attempt to get into the main.exe at workstation ABC. This is why I am using a flag file. I have to way to check the process running on another workstation.

ErocM
  • 4,505
  • 24
  • 94
  • 161
  • Massimiliano Peluso is right. Since you ARE ABLE TO open up main to check the flag, I don't see why you can't display a message as well. After you check the flag display a message. You are creating a new process when you open main so might as well piggy back on it a nag screen. – Adrian Mar 12 '12 at 16:12
  • If the main.exe remains open, the main.exe is now in use. I am immediately closing the main.exe so that it is NOT in use so that the update.exe can update the main.exe without getting an exception that the MAIN.EXE IS IN USE. That is the whole problem, I do not want to keep the main.exe running otherwise I will collide with it in my update.exe program. – ErocM Mar 12 '12 at 17:27
  • pop a nag screen w an OK button and inform the user they need to click OK in order for the update to complete. – Adrian Mar 12 '12 at 18:58

2 Answers2

1

I assume that when update.exe runs, it does not need to update itself? If that is the case, you can modify update.exe to invoke main.exe if no updates are necessary.

For instance, if an update is necessary(you can accomplish this via a adding a version number to your main.exe and checking it), update.exe will create your update.inprogress file and run the updates. Then if another instance of update.exe runs, it will see the update.inprogress file and alert the user that update is in progress and terminate itself without tying up main.exe. If update.exe runs when no updates are necessary and update.inprogress does not exist, it will invoke main.exe programmatically.

Bojin Li
  • 5,769
  • 2
  • 24
  • 37
  • @ErocM There might be some corner cases like what happens if main.exe is already running when you run update.exe, but I'm sure you can solve those as they come up. – Bojin Li Mar 12 '12 at 17:45
0

I would suggest to create a thread from your update.exe to check for the existence of your main.exe process. In case it shows up, alert the user with a message from your update.exe.

Reinaldo
  • 4,556
  • 3
  • 24
  • 24
  • I have added more to my question to clarify it. – ErocM Mar 12 '12 at 15:33
  • You can monitor the processes from your update.exe and notify the user if your main.exe is launched. See this to get an idea: http://stackoverflow.com/questions/1986249/c-sharp-process-monitor – Reinaldo Mar 12 '12 at 15:35