Ask Your Question
4

How can I run the same executable as the present instance in C# without using Process.Start()?

asked 2022-02-14 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-11-27 17:00:00 +0000

woof gravatar image

There are a few ways you can run the same executable as the present instance in C#, without using Process.Start(). Here are two ways:

  1. Use AppDomain.ExecuteAssembly():
AppDomain.CurrentDomain.ExecuteAssembly(Assembly.GetEntryAssembly().Location);

This will execute the same executable as the present instance.

  1. Use Reflection to call the main method:
MethodInfo method = typeof(Program).GetMethod("Main");
method.Invoke(null, null);

Replace "Program" with the name of your program class if it's different. This will call the Main() method of the same executable, effectively running it again.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-14 11:00:00 +0000

Seen: 9 times

Last updated: Nov 27 '22