How can I check to see if my program is already running

BlitzPlus Forums/BlitzPlus Programming/How can I check to see if my program is already running

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This is what I did at the beginning of my code.
Works like a charm.

Graphics 800,600,16,3
instance = ReadFile("instance.dat")
Read1 = ReadInt(instance)

If Read1 = 0
	;write 1 to file and continue with game
	instance = WriteFile("instance.dat")
	;SeekFile(instance,0)	
	WriteInt(instance,1)
	Read1 = ReadInt(instance)
	CloseFile(instance)
Else
	;if reaches here that means this game has already been
	;started and this instance should exit and end game
	CloseFile(instance)
	End
EndIf


And at the end of your code, before the End stmt put this.
instance = WriteFile("instance.dat")
Read1 = ReadInt(instance2)
WriteInt(instance1,0)
CloseFile(instance1)