Skip to content

Commit fccabd6

Browse files
committed
changes
1 parent 959db29 commit fccabd6

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

DontRunMe/Program.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11

22
// See https://aka.ms/new-console-template for more information
3+
using System.ComponentModel;
4+
using System.Diagnostics;
5+
using System.Reflection;
6+
37
Console.WriteLine("Hello, World!");
48

5-
string filename = "CSharpAndFSharp/DontRunMe.cs"; //read in file to run from user
6-
try
9+
string filename = $"{AssemblyDirectory}/DontRunMe.exe";
710
{
811
if (FourtyTwo(filename, args))
912
for (; ; );
1013
else
1114
return;
1215
}
13-
catch (OverflowException)
16+
catch (Win32Exception)
1417
{
1518
for (; ; );
1619
}
1720

1821
bool FourtyTwo(string filename, string[] args)
1922
{
20-
bool noanswer = true;
21-
int i = 0;
22-
while(noanswer)
23-
{
24-
checked
25-
{
26-
i++;
27-
}
28-
}
23+
var process = Process.Start(filename, args);
24+
process.WaitForExit();
2925
return true;
26+
}
27+
28+
string? AssemblyDirectory()
29+
{
30+
string codeBase = Assembly.GetExecutingAssembly().Location;
31+
UriBuilder uri = new UriBuilder(codeBase);
32+
string path = Uri.UnescapeDataString(uri.Path);
33+
return Path.GetDirectoryName(path);
3034
}

0 commit comments

Comments
 (0)