R
Randomity
Hi All
I have a web service that makes a Process.Start() call to start a long
running task that runs on the remote machine and I don't require any
further input from that machine. So I want my web method to return
immediately after the Process.Start() call. I have this configuration
on several machines now, and it works fine, except for one. It will
start the Process and wait for the end of its execution. Since this
can take up to a couple of hours, the service call times out and I get
an error, even if everything is running as planned.
Any ideas in this regard would be highly welcome!
Here's pretty much the code I have in my web service:
[WebMethod]
public void ImportData(string customer)
{
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
"Running Import for " + customer, EventLogEntryType.Information); //
Write messages to the event log of the system
try
{
using (Process importer = new Process())
{
importer.StartInfo.FileName =
ConfigurationManager.AppSettings["ImportEXEPath"];
importer.StartInfo.Arguments =
string.Format("folder:\"{0}\" customer:\"{1}\"",
ConfigurationManager.AppSettings["SettingsFolder"], customer); // Add
command line arguments for the process
if (!
string.IsNullOrEmpty(ConfigurationManager.AppSettings["args_rci"]))
importer.StartInfo.Arguments +=
string.Format(" code:{0}",
ConfigurationManager.AppSettings["args_rci"]); // Add some additional
arguments, if provided in the web.config
importer.StartInfo.UseShellExecute = false;
importer.StartInfo.RedirectStandardOutput = true;
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.sss") + " Starting Process
" + importer.StartInfo.FileName);
importer.Start();
// The web method should return immediately now,
instead it takes forever to return and then times out
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
importer.StandardOutput.ReadToEnd(), EventLogEntryType.Warning); // I
added this line to see what the process was doing, since it didn't
return for a long time. It was the output coming from my command line
application, which means it's a synchronous call (instead kind of fire-
and-forget)
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
"Process started successfully", EventLogEntryType.SuccessAudit);
}
}
catch (Exception ex)
{
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
ex.Message, EventLogEntryType.Error);
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
ex.StackTrace, EventLogEntryType.Error);
}
}
The method executes without any errors/exceptions, I can view all the
log entries, including the "Process started successfully" in the Event
Viewer.
Thanks for the help
Dominik
I have a web service that makes a Process.Start() call to start a long
running task that runs on the remote machine and I don't require any
further input from that machine. So I want my web method to return
immediately after the Process.Start() call. I have this configuration
on several machines now, and it works fine, except for one. It will
start the Process and wait for the end of its execution. Since this
can take up to a couple of hours, the service call times out and I get
an error, even if everything is running as planned.
Any ideas in this regard would be highly welcome!
Here's pretty much the code I have in my web service:
[WebMethod]
public void ImportData(string customer)
{
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
"Running Import for " + customer, EventLogEntryType.Information); //
Write messages to the event log of the system
try
{
using (Process importer = new Process())
{
importer.StartInfo.FileName =
ConfigurationManager.AppSettings["ImportEXEPath"];
importer.StartInfo.Arguments =
string.Format("folder:\"{0}\" customer:\"{1}\"",
ConfigurationManager.AppSettings["SettingsFolder"], customer); // Add
command line arguments for the process
if (!
string.IsNullOrEmpty(ConfigurationManager.AppSettings["args_rci"]))
importer.StartInfo.Arguments +=
string.Format(" code:{0}",
ConfigurationManager.AppSettings["args_rci"]); // Add some additional
arguments, if provided in the web.config
importer.StartInfo.UseShellExecute = false;
importer.StartInfo.RedirectStandardOutput = true;
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.sss") + " Starting Process
" + importer.StartInfo.FileName);
importer.Start();
// The web method should return immediately now,
instead it takes forever to return and then times out
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
importer.StandardOutput.ReadToEnd(), EventLogEntryType.Warning); // I
added this line to see what the process was doing, since it didn't
return for a long time. It was the output coming from my command line
application, which means it's a synchronous call (instead kind of fire-
and-forget)
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
"Process started successfully", EventLogEntryType.SuccessAudit);
}
}
catch (Exception ex)
{
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
ex.Message, EventLogEntryType.Error);
EventLog.WriteEntry(ConfigurationManager.AppSettings["LogSource"],
ex.StackTrace, EventLogEntryType.Error);
}
}
The method executes without any errors/exceptions, I can view all the
log entries, including the "Process started successfully" in the Event
Viewer.
Thanks for the help
Dominik