Answer the question
In order to leave comments, you need to log in
How to make a permanent background Process in C#?
In general, everything is very simple ...
try
{
psi.FileName = @"C:/Users/User/AppData/Local/Programs/Python/Python38-32/python.exe";
var PyScript = @"Load.py";
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.Arguments = $"\"{PyScript}\"";
var errors = "";
var output = "";
using (var process = Process.Start(psi))
{
errors = process.StandardError.ReadToEnd();
output = process.StandardOutput.ReadToEnd();
}
richTextBox2.AppendText(errors);
richTextBox2.AppendText(output);
}
catch (Exception eU)
{
// Сообщение о ошибке
MessageBox.Show(eU.Message);
// Информаци о ошибке
MessageBox.Show(eU.ToString());
}
from datetime import datetime
import sys
import pytz
import time
j = 0
while(True):
time.sleep(0.5)
print("Next step " + str(j))
j = j + 1
if(j > 10):
break
Answer the question
In order to leave comments, you need to log in
Look towards the Background Process
And there is also a Quartz.NET library
Because the ReadToEnd method blocks the thread until it has read the entire stream to the end
. Use ReadLineAsync or ReadToEndAsync to read data asynchronously.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question