Why does my C# Process sometimes work, and sometimes hang indefinitely?












1















I've got a block of code that runs inside C# and creates a Process for decompressing (un-gzipping and un-taring) a file. On a fresh reboot of my computer, I can call the block of code below and my file is decompressed within a second or two. However, at some point, the code below completely stops working (until I do a reboot).



Process bashProcess = new Process();
bashProcess.StartInfo.FileName = ConfigurationManager.AppSettings["Util.CygwinPath"];
bashProcess.StartInfo.Arguments = String.Format(
"--login -c "tar --overwrite --gzip --directory={0} -xf {1}"",
unixPath.Replace(fileName, ""), unixPath);
bashProcess.StartInfo.RedirectStandardError = true;
bashProcess.StartInfo.RedirectStandardInput = true;
bashProcess.StartInfo.RedirectStandardOutput = true;
bashProcess.StartInfo.CreateNoWindow = true;
bashProcess.StartInfo.UseShellExecute = false;
bashProcess.StartInfo.ErrorDialog = false;

bashProcess.Start();
bashProcess.WaitForExit(10000);


I've tried a few things, including:




  • Grabbing the StandardOutput and logging it, to clear its buffer. (nothing was logged)

  • Grabbing the StandardError and logging it, to clear its buffer. (nothing was logged)

  • Killing the process afterwards (manually and programatically) in case a previous process was holding on to the file I'm decompressing.

  • Deleting and reinstalling the file I'm decompressing, in case it was being held onto by a zombie process.


What could cause the Process to just not work? It doesn't error out, it just hangs indefinitely until the timeout from WaitForExit(10000) is hit.



UPDATE



I'm not logging the final value of bashProcess.StartInfo.Arguments but I have grabbed that value and ensured Cygwin can run it. When ran from Cygwin, the file decompresses as expected. The full command looks like this:



bash.exe --login -c "tar --overwrite --gzip --directory=/cygdrive/mypath/mydir -xf /cygdrive/mypath/mydir/myfile.tar.gz"


I am running the code above straight from Visual Studio 2015.



One other weird thing I've noticed on my machine is that Cygwin's boot time is variable. Right after a fresh reboot, Cygwin can be opened in seconds. After my computer has been running for a while, Cygwin can take upwards of 3 or 5 minutes to open. I wonder if Cygwin's load time and my problem in this question are related?



UPDATE 2



It does appear that my computer's increased slowdown of Cygwin is the source of the problem, although I don't know why Cygwin slows down over time. I noticed that my code above did eventually complete but it took several minutes longer than expected (code above should complete in 1-2 seconds).










share|improve this question

























  • What is the final value of bashProcess.StartInfo.Arguments when it fails? Are you logging it? When it starts happening, have you tried running Cygwin manually (outside of C#) and run that command there? What happens there?

    – mjwills
    Nov 15 '18 at 20:46











  • Is this process start at logon or logon after reboot or are you literally opening VS and press F5 ?

    – Franck
    Nov 15 '18 at 20:46
















1















I've got a block of code that runs inside C# and creates a Process for decompressing (un-gzipping and un-taring) a file. On a fresh reboot of my computer, I can call the block of code below and my file is decompressed within a second or two. However, at some point, the code below completely stops working (until I do a reboot).



Process bashProcess = new Process();
bashProcess.StartInfo.FileName = ConfigurationManager.AppSettings["Util.CygwinPath"];
bashProcess.StartInfo.Arguments = String.Format(
"--login -c "tar --overwrite --gzip --directory={0} -xf {1}"",
unixPath.Replace(fileName, ""), unixPath);
bashProcess.StartInfo.RedirectStandardError = true;
bashProcess.StartInfo.RedirectStandardInput = true;
bashProcess.StartInfo.RedirectStandardOutput = true;
bashProcess.StartInfo.CreateNoWindow = true;
bashProcess.StartInfo.UseShellExecute = false;
bashProcess.StartInfo.ErrorDialog = false;

bashProcess.Start();
bashProcess.WaitForExit(10000);


I've tried a few things, including:




  • Grabbing the StandardOutput and logging it, to clear its buffer. (nothing was logged)

  • Grabbing the StandardError and logging it, to clear its buffer. (nothing was logged)

  • Killing the process afterwards (manually and programatically) in case a previous process was holding on to the file I'm decompressing.

  • Deleting and reinstalling the file I'm decompressing, in case it was being held onto by a zombie process.


What could cause the Process to just not work? It doesn't error out, it just hangs indefinitely until the timeout from WaitForExit(10000) is hit.



UPDATE



I'm not logging the final value of bashProcess.StartInfo.Arguments but I have grabbed that value and ensured Cygwin can run it. When ran from Cygwin, the file decompresses as expected. The full command looks like this:



bash.exe --login -c "tar --overwrite --gzip --directory=/cygdrive/mypath/mydir -xf /cygdrive/mypath/mydir/myfile.tar.gz"


I am running the code above straight from Visual Studio 2015.



One other weird thing I've noticed on my machine is that Cygwin's boot time is variable. Right after a fresh reboot, Cygwin can be opened in seconds. After my computer has been running for a while, Cygwin can take upwards of 3 or 5 minutes to open. I wonder if Cygwin's load time and my problem in this question are related?



UPDATE 2



It does appear that my computer's increased slowdown of Cygwin is the source of the problem, although I don't know why Cygwin slows down over time. I noticed that my code above did eventually complete but it took several minutes longer than expected (code above should complete in 1-2 seconds).










share|improve this question

























  • What is the final value of bashProcess.StartInfo.Arguments when it fails? Are you logging it? When it starts happening, have you tried running Cygwin manually (outside of C#) and run that command there? What happens there?

    – mjwills
    Nov 15 '18 at 20:46











  • Is this process start at logon or logon after reboot or are you literally opening VS and press F5 ?

    – Franck
    Nov 15 '18 at 20:46














1












1








1








I've got a block of code that runs inside C# and creates a Process for decompressing (un-gzipping and un-taring) a file. On a fresh reboot of my computer, I can call the block of code below and my file is decompressed within a second or two. However, at some point, the code below completely stops working (until I do a reboot).



Process bashProcess = new Process();
bashProcess.StartInfo.FileName = ConfigurationManager.AppSettings["Util.CygwinPath"];
bashProcess.StartInfo.Arguments = String.Format(
"--login -c "tar --overwrite --gzip --directory={0} -xf {1}"",
unixPath.Replace(fileName, ""), unixPath);
bashProcess.StartInfo.RedirectStandardError = true;
bashProcess.StartInfo.RedirectStandardInput = true;
bashProcess.StartInfo.RedirectStandardOutput = true;
bashProcess.StartInfo.CreateNoWindow = true;
bashProcess.StartInfo.UseShellExecute = false;
bashProcess.StartInfo.ErrorDialog = false;

bashProcess.Start();
bashProcess.WaitForExit(10000);


I've tried a few things, including:




  • Grabbing the StandardOutput and logging it, to clear its buffer. (nothing was logged)

  • Grabbing the StandardError and logging it, to clear its buffer. (nothing was logged)

  • Killing the process afterwards (manually and programatically) in case a previous process was holding on to the file I'm decompressing.

  • Deleting and reinstalling the file I'm decompressing, in case it was being held onto by a zombie process.


What could cause the Process to just not work? It doesn't error out, it just hangs indefinitely until the timeout from WaitForExit(10000) is hit.



UPDATE



I'm not logging the final value of bashProcess.StartInfo.Arguments but I have grabbed that value and ensured Cygwin can run it. When ran from Cygwin, the file decompresses as expected. The full command looks like this:



bash.exe --login -c "tar --overwrite --gzip --directory=/cygdrive/mypath/mydir -xf /cygdrive/mypath/mydir/myfile.tar.gz"


I am running the code above straight from Visual Studio 2015.



One other weird thing I've noticed on my machine is that Cygwin's boot time is variable. Right after a fresh reboot, Cygwin can be opened in seconds. After my computer has been running for a while, Cygwin can take upwards of 3 or 5 minutes to open. I wonder if Cygwin's load time and my problem in this question are related?



UPDATE 2



It does appear that my computer's increased slowdown of Cygwin is the source of the problem, although I don't know why Cygwin slows down over time. I noticed that my code above did eventually complete but it took several minutes longer than expected (code above should complete in 1-2 seconds).










share|improve this question
















I've got a block of code that runs inside C# and creates a Process for decompressing (un-gzipping and un-taring) a file. On a fresh reboot of my computer, I can call the block of code below and my file is decompressed within a second or two. However, at some point, the code below completely stops working (until I do a reboot).



Process bashProcess = new Process();
bashProcess.StartInfo.FileName = ConfigurationManager.AppSettings["Util.CygwinPath"];
bashProcess.StartInfo.Arguments = String.Format(
"--login -c "tar --overwrite --gzip --directory={0} -xf {1}"",
unixPath.Replace(fileName, ""), unixPath);
bashProcess.StartInfo.RedirectStandardError = true;
bashProcess.StartInfo.RedirectStandardInput = true;
bashProcess.StartInfo.RedirectStandardOutput = true;
bashProcess.StartInfo.CreateNoWindow = true;
bashProcess.StartInfo.UseShellExecute = false;
bashProcess.StartInfo.ErrorDialog = false;

bashProcess.Start();
bashProcess.WaitForExit(10000);


I've tried a few things, including:




  • Grabbing the StandardOutput and logging it, to clear its buffer. (nothing was logged)

  • Grabbing the StandardError and logging it, to clear its buffer. (nothing was logged)

  • Killing the process afterwards (manually and programatically) in case a previous process was holding on to the file I'm decompressing.

  • Deleting and reinstalling the file I'm decompressing, in case it was being held onto by a zombie process.


What could cause the Process to just not work? It doesn't error out, it just hangs indefinitely until the timeout from WaitForExit(10000) is hit.



UPDATE



I'm not logging the final value of bashProcess.StartInfo.Arguments but I have grabbed that value and ensured Cygwin can run it. When ran from Cygwin, the file decompresses as expected. The full command looks like this:



bash.exe --login -c "tar --overwrite --gzip --directory=/cygdrive/mypath/mydir -xf /cygdrive/mypath/mydir/myfile.tar.gz"


I am running the code above straight from Visual Studio 2015.



One other weird thing I've noticed on my machine is that Cygwin's boot time is variable. Right after a fresh reboot, Cygwin can be opened in seconds. After my computer has been running for a while, Cygwin can take upwards of 3 or 5 minutes to open. I wonder if Cygwin's load time and my problem in this question are related?



UPDATE 2



It does appear that my computer's increased slowdown of Cygwin is the source of the problem, although I don't know why Cygwin slows down over time. I noticed that my code above did eventually complete but it took several minutes longer than expected (code above should complete in 1-2 seconds).







c# process






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 21:05







Max

















asked Nov 15 '18 at 20:41









MaxMax

13812




13812













  • What is the final value of bashProcess.StartInfo.Arguments when it fails? Are you logging it? When it starts happening, have you tried running Cygwin manually (outside of C#) and run that command there? What happens there?

    – mjwills
    Nov 15 '18 at 20:46











  • Is this process start at logon or logon after reboot or are you literally opening VS and press F5 ?

    – Franck
    Nov 15 '18 at 20:46



















  • What is the final value of bashProcess.StartInfo.Arguments when it fails? Are you logging it? When it starts happening, have you tried running Cygwin manually (outside of C#) and run that command there? What happens there?

    – mjwills
    Nov 15 '18 at 20:46











  • Is this process start at logon or logon after reboot or are you literally opening VS and press F5 ?

    – Franck
    Nov 15 '18 at 20:46

















What is the final value of bashProcess.StartInfo.Arguments when it fails? Are you logging it? When it starts happening, have you tried running Cygwin manually (outside of C#) and run that command there? What happens there?

– mjwills
Nov 15 '18 at 20:46





What is the final value of bashProcess.StartInfo.Arguments when it fails? Are you logging it? When it starts happening, have you tried running Cygwin manually (outside of C#) and run that command there? What happens there?

– mjwills
Nov 15 '18 at 20:46













Is this process start at logon or logon after reboot or are you literally opening VS and press F5 ?

– Franck
Nov 15 '18 at 20:46





Is this process start at logon or logon after reboot or are you literally opening VS and press F5 ?

– Franck
Nov 15 '18 at 20:46












0






active

oldest

votes











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327598%2fwhy-does-my-c-sharp-process-sometimes-work-and-sometimes-hang-indefinitely%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327598%2fwhy-does-my-c-sharp-process-sometimes-work-and-sometimes-hang-indefinitely%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python