C# Pause one console application when other console application starts
I have one console application for testing purposes like following:
static void Main(string args)
do
for (int i = 0; i < 10000000; i++)
Console.WriteLine("Doing some endless loop");
Console.WriteLine(i.ToString());
while (true);
As you can see the code is very basic, and I've set it up to endless loop in order to test what I would like to achieve.
The other console application is called "Updater" and I would like to to pause the "EndlessLoop" console application once the "Updater" application is started.
Does anyone knows if this is doable in c# .NET?
c# process console console-application pause
|
show 2 more comments
I have one console application for testing purposes like following:
static void Main(string args)
do
for (int i = 0; i < 10000000; i++)
Console.WriteLine("Doing some endless loop");
Console.WriteLine(i.ToString());
while (true);
As you can see the code is very basic, and I've set it up to endless loop in order to test what I would like to achieve.
The other console application is called "Updater" and I would like to to pause the "EndlessLoop" console application once the "Updater" application is started.
Does anyone knows if this is doable in c# .NET?
c# process console console-application pause
1
Do you want to pause this application, or you want to kill this application?
– Jim Mischel
Nov 13 '18 at 15:01
1
if (Process.GetProcessesByName("Updater.exe").Any()) //pause your code?
– Rand Random
Nov 13 '18 at 15:01
2
To actually control synchronization between the two apps you could use a named mutex.
– 500 - Internal Server Error
Nov 13 '18 at 15:02
1
Take a look at Mutex class.
– Alessandro D'Andria
Nov 13 '18 at 15:03
1
Not a duplicate, but somehow relevant: stackoverflow.com/questions/9803432/…
– nilsK
Nov 13 '18 at 15:04
|
show 2 more comments
I have one console application for testing purposes like following:
static void Main(string args)
do
for (int i = 0; i < 10000000; i++)
Console.WriteLine("Doing some endless loop");
Console.WriteLine(i.ToString());
while (true);
As you can see the code is very basic, and I've set it up to endless loop in order to test what I would like to achieve.
The other console application is called "Updater" and I would like to to pause the "EndlessLoop" console application once the "Updater" application is started.
Does anyone knows if this is doable in c# .NET?
c# process console console-application pause
I have one console application for testing purposes like following:
static void Main(string args)
do
for (int i = 0; i < 10000000; i++)
Console.WriteLine("Doing some endless loop");
Console.WriteLine(i.ToString());
while (true);
As you can see the code is very basic, and I've set it up to endless loop in order to test what I would like to achieve.
The other console application is called "Updater" and I would like to to pause the "EndlessLoop" console application once the "Updater" application is started.
Does anyone knows if this is doable in c# .NET?
c# process console console-application pause
c# process console console-application pause
edited Nov 13 '18 at 14:59
Rand Random
2,97573163
2,97573163
asked Nov 13 '18 at 14:57
User987User987
1,34232045
1,34232045
1
Do you want to pause this application, or you want to kill this application?
– Jim Mischel
Nov 13 '18 at 15:01
1
if (Process.GetProcessesByName("Updater.exe").Any()) //pause your code?
– Rand Random
Nov 13 '18 at 15:01
2
To actually control synchronization between the two apps you could use a named mutex.
– 500 - Internal Server Error
Nov 13 '18 at 15:02
1
Take a look at Mutex class.
– Alessandro D'Andria
Nov 13 '18 at 15:03
1
Not a duplicate, but somehow relevant: stackoverflow.com/questions/9803432/…
– nilsK
Nov 13 '18 at 15:04
|
show 2 more comments
1
Do you want to pause this application, or you want to kill this application?
– Jim Mischel
Nov 13 '18 at 15:01
1
if (Process.GetProcessesByName("Updater.exe").Any()) //pause your code?
– Rand Random
Nov 13 '18 at 15:01
2
To actually control synchronization between the two apps you could use a named mutex.
– 500 - Internal Server Error
Nov 13 '18 at 15:02
1
Take a look at Mutex class.
– Alessandro D'Andria
Nov 13 '18 at 15:03
1
Not a duplicate, but somehow relevant: stackoverflow.com/questions/9803432/…
– nilsK
Nov 13 '18 at 15:04
1
1
Do you want to pause this application, or you want to kill this application?
– Jim Mischel
Nov 13 '18 at 15:01
Do you want to pause this application, or you want to kill this application?
– Jim Mischel
Nov 13 '18 at 15:01
1
1
if (Process.GetProcessesByName("Updater.exe").Any()) //pause your code ?– Rand Random
Nov 13 '18 at 15:01
if (Process.GetProcessesByName("Updater.exe").Any()) //pause your code ?– Rand Random
Nov 13 '18 at 15:01
2
2
To actually control synchronization between the two apps you could use a named mutex.
– 500 - Internal Server Error
Nov 13 '18 at 15:02
To actually control synchronization between the two apps you could use a named mutex.
– 500 - Internal Server Error
Nov 13 '18 at 15:02
1
1
Take a look at Mutex class.
– Alessandro D'Andria
Nov 13 '18 at 15:03
Take a look at Mutex class.
– Alessandro D'Andria
Nov 13 '18 at 15:03
1
1
Not a duplicate, but somehow relevant: stackoverflow.com/questions/9803432/…
– nilsK
Nov 13 '18 at 15:04
Not a duplicate, but somehow relevant: stackoverflow.com/questions/9803432/…
– nilsK
Nov 13 '18 at 15:04
|
show 2 more comments
2 Answers
2
active
oldest
votes
public static bool IsAppRunning()
foreach (Process process in Process.GetProcesses())
if (process.ProcessName.Contains("Updater"))
return true;
return false;
If you call this in while loop it tells you if Updater is running or not.
Two problems. 1) a busy-wait loop is a waste of resources. 2) Using "Contains" to find the process name is just begging for problems. For example, if some other process called "CriticalFileUpdater" starts, your code is going to returntruewhen it shouldn't.
– Jim Mischel
Nov 13 '18 at 15:14
busy loop wait, yeah, use sleep or anything and wont be busy. Use Equals("Updater.exe") then...
– János Tigyi
Nov 13 '18 at 15:15
Why hack together something when there are simple and reliable tools that are made specifically for this job? Even a sleep loop is a busy wait; it's just a bit less busy than a loop without a sleep. Use the right tool for the job.
– Jim Mischel
Nov 13 '18 at 15:18
Wich tool? If you say use the right tool, than say wich one? I don't think you need to optimize this small code, that called micro optimization, 'cos it's so simple and light.
– János Tigyi
Nov 13 '18 at 15:20
EventWaitHandlestackoverflow.com/a/480707/56778
– Jim Mischel
Nov 13 '18 at 15:29
|
show 1 more comment
Not easy to communicate between 2 application
One proposition: When your console Updater starts, you create a file in folder C:Tempstoken.txt. Then, if your console EndlessLoop detects a file names token.txt in C:Temps, you pause EndlessLoop
1
Communication between applications is not at all difficult. There are many examples of using named events in C# for inter-application communication. See, for example, stackoverflow.com/q/480430/56778.
– Jim Mischel
Nov 13 '18 at 15:03
@JimMischel yes, but I think my proposition is still simple
– Antoine V
Nov 13 '18 at 15:06
Yes, it's simple. It also requires a busy wait loop or aFileSystemWatcher, and can fail if somebody deletes the file or creates it when not expected. It'll work for a non-critical system, but is not at all reliable. I certainly wouldn't recommend using the file system for real-time inter-app communication. Especially when using a named event handle is simple and reliable.
– Jim Mischel
Nov 13 '18 at 15:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283781%2fc-sharp-pause-one-console-application-when-other-console-application-starts%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
public static bool IsAppRunning()
foreach (Process process in Process.GetProcesses())
if (process.ProcessName.Contains("Updater"))
return true;
return false;
If you call this in while loop it tells you if Updater is running or not.
Two problems. 1) a busy-wait loop is a waste of resources. 2) Using "Contains" to find the process name is just begging for problems. For example, if some other process called "CriticalFileUpdater" starts, your code is going to returntruewhen it shouldn't.
– Jim Mischel
Nov 13 '18 at 15:14
busy loop wait, yeah, use sleep or anything and wont be busy. Use Equals("Updater.exe") then...
– János Tigyi
Nov 13 '18 at 15:15
Why hack together something when there are simple and reliable tools that are made specifically for this job? Even a sleep loop is a busy wait; it's just a bit less busy than a loop without a sleep. Use the right tool for the job.
– Jim Mischel
Nov 13 '18 at 15:18
Wich tool? If you say use the right tool, than say wich one? I don't think you need to optimize this small code, that called micro optimization, 'cos it's so simple and light.
– János Tigyi
Nov 13 '18 at 15:20
EventWaitHandlestackoverflow.com/a/480707/56778
– Jim Mischel
Nov 13 '18 at 15:29
|
show 1 more comment
public static bool IsAppRunning()
foreach (Process process in Process.GetProcesses())
if (process.ProcessName.Contains("Updater"))
return true;
return false;
If you call this in while loop it tells you if Updater is running or not.
Two problems. 1) a busy-wait loop is a waste of resources. 2) Using "Contains" to find the process name is just begging for problems. For example, if some other process called "CriticalFileUpdater" starts, your code is going to returntruewhen it shouldn't.
– Jim Mischel
Nov 13 '18 at 15:14
busy loop wait, yeah, use sleep or anything and wont be busy. Use Equals("Updater.exe") then...
– János Tigyi
Nov 13 '18 at 15:15
Why hack together something when there are simple and reliable tools that are made specifically for this job? Even a sleep loop is a busy wait; it's just a bit less busy than a loop without a sleep. Use the right tool for the job.
– Jim Mischel
Nov 13 '18 at 15:18
Wich tool? If you say use the right tool, than say wich one? I don't think you need to optimize this small code, that called micro optimization, 'cos it's so simple and light.
– János Tigyi
Nov 13 '18 at 15:20
EventWaitHandlestackoverflow.com/a/480707/56778
– Jim Mischel
Nov 13 '18 at 15:29
|
show 1 more comment
public static bool IsAppRunning()
foreach (Process process in Process.GetProcesses())
if (process.ProcessName.Contains("Updater"))
return true;
return false;
If you call this in while loop it tells you if Updater is running or not.
public static bool IsAppRunning()
foreach (Process process in Process.GetProcesses())
if (process.ProcessName.Contains("Updater"))
return true;
return false;
If you call this in while loop it tells you if Updater is running or not.
answered Nov 13 '18 at 15:06
János TigyiJános Tigyi
77518
77518
Two problems. 1) a busy-wait loop is a waste of resources. 2) Using "Contains" to find the process name is just begging for problems. For example, if some other process called "CriticalFileUpdater" starts, your code is going to returntruewhen it shouldn't.
– Jim Mischel
Nov 13 '18 at 15:14
busy loop wait, yeah, use sleep or anything and wont be busy. Use Equals("Updater.exe") then...
– János Tigyi
Nov 13 '18 at 15:15
Why hack together something when there are simple and reliable tools that are made specifically for this job? Even a sleep loop is a busy wait; it's just a bit less busy than a loop without a sleep. Use the right tool for the job.
– Jim Mischel
Nov 13 '18 at 15:18
Wich tool? If you say use the right tool, than say wich one? I don't think you need to optimize this small code, that called micro optimization, 'cos it's so simple and light.
– János Tigyi
Nov 13 '18 at 15:20
EventWaitHandlestackoverflow.com/a/480707/56778
– Jim Mischel
Nov 13 '18 at 15:29
|
show 1 more comment
Two problems. 1) a busy-wait loop is a waste of resources. 2) Using "Contains" to find the process name is just begging for problems. For example, if some other process called "CriticalFileUpdater" starts, your code is going to returntruewhen it shouldn't.
– Jim Mischel
Nov 13 '18 at 15:14
busy loop wait, yeah, use sleep or anything and wont be busy. Use Equals("Updater.exe") then...
– János Tigyi
Nov 13 '18 at 15:15
Why hack together something when there are simple and reliable tools that are made specifically for this job? Even a sleep loop is a busy wait; it's just a bit less busy than a loop without a sleep. Use the right tool for the job.
– Jim Mischel
Nov 13 '18 at 15:18
Wich tool? If you say use the right tool, than say wich one? I don't think you need to optimize this small code, that called micro optimization, 'cos it's so simple and light.
– János Tigyi
Nov 13 '18 at 15:20
EventWaitHandlestackoverflow.com/a/480707/56778
– Jim Mischel
Nov 13 '18 at 15:29
Two problems. 1) a busy-wait loop is a waste of resources. 2) Using "Contains" to find the process name is just begging for problems. For example, if some other process called "CriticalFileUpdater" starts, your code is going to return
true when it shouldn't.– Jim Mischel
Nov 13 '18 at 15:14
Two problems. 1) a busy-wait loop is a waste of resources. 2) Using "Contains" to find the process name is just begging for problems. For example, if some other process called "CriticalFileUpdater" starts, your code is going to return
true when it shouldn't.– Jim Mischel
Nov 13 '18 at 15:14
busy loop wait, yeah, use sleep or anything and wont be busy. Use Equals("Updater.exe") then...
– János Tigyi
Nov 13 '18 at 15:15
busy loop wait, yeah, use sleep or anything and wont be busy. Use Equals("Updater.exe") then...
– János Tigyi
Nov 13 '18 at 15:15
Why hack together something when there are simple and reliable tools that are made specifically for this job? Even a sleep loop is a busy wait; it's just a bit less busy than a loop without a sleep. Use the right tool for the job.
– Jim Mischel
Nov 13 '18 at 15:18
Why hack together something when there are simple and reliable tools that are made specifically for this job? Even a sleep loop is a busy wait; it's just a bit less busy than a loop without a sleep. Use the right tool for the job.
– Jim Mischel
Nov 13 '18 at 15:18
Wich tool? If you say use the right tool, than say wich one? I don't think you need to optimize this small code, that called micro optimization, 'cos it's so simple and light.
– János Tigyi
Nov 13 '18 at 15:20
Wich tool? If you say use the right tool, than say wich one? I don't think you need to optimize this small code, that called micro optimization, 'cos it's so simple and light.
– János Tigyi
Nov 13 '18 at 15:20
EventWaitHandle stackoverflow.com/a/480707/56778– Jim Mischel
Nov 13 '18 at 15:29
EventWaitHandle stackoverflow.com/a/480707/56778– Jim Mischel
Nov 13 '18 at 15:29
|
show 1 more comment
Not easy to communicate between 2 application
One proposition: When your console Updater starts, you create a file in folder C:Tempstoken.txt. Then, if your console EndlessLoop detects a file names token.txt in C:Temps, you pause EndlessLoop
1
Communication between applications is not at all difficult. There are many examples of using named events in C# for inter-application communication. See, for example, stackoverflow.com/q/480430/56778.
– Jim Mischel
Nov 13 '18 at 15:03
@JimMischel yes, but I think my proposition is still simple
– Antoine V
Nov 13 '18 at 15:06
Yes, it's simple. It also requires a busy wait loop or aFileSystemWatcher, and can fail if somebody deletes the file or creates it when not expected. It'll work for a non-critical system, but is not at all reliable. I certainly wouldn't recommend using the file system for real-time inter-app communication. Especially when using a named event handle is simple and reliable.
– Jim Mischel
Nov 13 '18 at 15:11
add a comment |
Not easy to communicate between 2 application
One proposition: When your console Updater starts, you create a file in folder C:Tempstoken.txt. Then, if your console EndlessLoop detects a file names token.txt in C:Temps, you pause EndlessLoop
1
Communication between applications is not at all difficult. There are many examples of using named events in C# for inter-application communication. See, for example, stackoverflow.com/q/480430/56778.
– Jim Mischel
Nov 13 '18 at 15:03
@JimMischel yes, but I think my proposition is still simple
– Antoine V
Nov 13 '18 at 15:06
Yes, it's simple. It also requires a busy wait loop or aFileSystemWatcher, and can fail if somebody deletes the file or creates it when not expected. It'll work for a non-critical system, but is not at all reliable. I certainly wouldn't recommend using the file system for real-time inter-app communication. Especially when using a named event handle is simple and reliable.
– Jim Mischel
Nov 13 '18 at 15:11
add a comment |
Not easy to communicate between 2 application
One proposition: When your console Updater starts, you create a file in folder C:Tempstoken.txt. Then, if your console EndlessLoop detects a file names token.txt in C:Temps, you pause EndlessLoop
Not easy to communicate between 2 application
One proposition: When your console Updater starts, you create a file in folder C:Tempstoken.txt. Then, if your console EndlessLoop detects a file names token.txt in C:Temps, you pause EndlessLoop
answered Nov 13 '18 at 15:01
Antoine VAntoine V
5,1142424
5,1142424
1
Communication between applications is not at all difficult. There are many examples of using named events in C# for inter-application communication. See, for example, stackoverflow.com/q/480430/56778.
– Jim Mischel
Nov 13 '18 at 15:03
@JimMischel yes, but I think my proposition is still simple
– Antoine V
Nov 13 '18 at 15:06
Yes, it's simple. It also requires a busy wait loop or aFileSystemWatcher, and can fail if somebody deletes the file or creates it when not expected. It'll work for a non-critical system, but is not at all reliable. I certainly wouldn't recommend using the file system for real-time inter-app communication. Especially when using a named event handle is simple and reliable.
– Jim Mischel
Nov 13 '18 at 15:11
add a comment |
1
Communication between applications is not at all difficult. There are many examples of using named events in C# for inter-application communication. See, for example, stackoverflow.com/q/480430/56778.
– Jim Mischel
Nov 13 '18 at 15:03
@JimMischel yes, but I think my proposition is still simple
– Antoine V
Nov 13 '18 at 15:06
Yes, it's simple. It also requires a busy wait loop or aFileSystemWatcher, and can fail if somebody deletes the file or creates it when not expected. It'll work for a non-critical system, but is not at all reliable. I certainly wouldn't recommend using the file system for real-time inter-app communication. Especially when using a named event handle is simple and reliable.
– Jim Mischel
Nov 13 '18 at 15:11
1
1
Communication between applications is not at all difficult. There are many examples of using named events in C# for inter-application communication. See, for example, stackoverflow.com/q/480430/56778.
– Jim Mischel
Nov 13 '18 at 15:03
Communication between applications is not at all difficult. There are many examples of using named events in C# for inter-application communication. See, for example, stackoverflow.com/q/480430/56778.
– Jim Mischel
Nov 13 '18 at 15:03
@JimMischel yes, but I think my proposition is still simple
– Antoine V
Nov 13 '18 at 15:06
@JimMischel yes, but I think my proposition is still simple
– Antoine V
Nov 13 '18 at 15:06
Yes, it's simple. It also requires a busy wait loop or a
FileSystemWatcher, and can fail if somebody deletes the file or creates it when not expected. It'll work for a non-critical system, but is not at all reliable. I certainly wouldn't recommend using the file system for real-time inter-app communication. Especially when using a named event handle is simple and reliable.– Jim Mischel
Nov 13 '18 at 15:11
Yes, it's simple. It also requires a busy wait loop or a
FileSystemWatcher, and can fail if somebody deletes the file or creates it when not expected. It'll work for a non-critical system, but is not at all reliable. I certainly wouldn't recommend using the file system for real-time inter-app communication. Especially when using a named event handle is simple and reliable.– Jim Mischel
Nov 13 '18 at 15:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283781%2fc-sharp-pause-one-console-application-when-other-console-application-starts%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Do you want to pause this application, or you want to kill this application?
– Jim Mischel
Nov 13 '18 at 15:01
1
if (Process.GetProcessesByName("Updater.exe").Any()) //pause your code?– Rand Random
Nov 13 '18 at 15:01
2
To actually control synchronization between the two apps you could use a named mutex.
– 500 - Internal Server Error
Nov 13 '18 at 15:02
1
Take a look at Mutex class.
– Alessandro D'Andria
Nov 13 '18 at 15:03
1
Not a duplicate, but somehow relevant: stackoverflow.com/questions/9803432/…
– nilsK
Nov 13 '18 at 15:04