Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > C# 4.0 aka C# 2010 General Discussion
|
C# 4.0 aka C# 2010 General Discussion Discussions about the C# 4.0, C# 4, Visual C# 2010 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 4.0 aka C# 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2011, 09:07 AM
Authorized User
 
Join Date: Jun 2003
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default Detaching the client from long running processes

Hi All,

I originally wrote a standard c#4.0 web app, however because the client was designed essentially to run a batch process I was receiving time out issues because the batch process can take anything up to a couple of hours. I moved the long running process out to a WCF Service Library, but because just leaving it there would leave the potential for time out issues under IIS I created a windows Service Wrapper to the WCF Service.I still seem to be having time out issues because everything wants to run Async when really I want to run Syncronously such that once I have called my windows service method from the client I want the process to continue in the background and I dont care that the client may close their browser or even turn their machine off. So to show some code:

Initially In my windows server I was using a background worked, but that was specifically designed for Async, so I changed to a normal 'Create new Thread' method, but that's still the same, I've been looking at some of the new features in.net 4.0 such as tasks etc, but they all assume that the parent thread is still running and if that is destroyed then so do these (that said when my code runs, that's not quite true).

so first off, in my WCF Service I have just 1 method on the interface:

Code:

[ServiceContract]
public interfaceIRS
{
[OperationContract(IsOneWay=true)]
void ProcessBorderaux();
and in the declaration to the service class I have adorned a ServiceBehaviour:

Code:

[ServiceBehavior(AutomaticSessionShutdown = false, UseSynchronizationContext = false, InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
public classIRSService : IRS
{
No up a level to my windows Service in my OnStart event:
Code:

protected override void OnStart(string[] args)
{
   Thread t = newThread(newThreadStart(RunService));
   try
   {
     t.TrySetApartmentState(ApartmentState.STA);
     t.Start();
   }
   catch
   {
     if (t.IsAlive) { t.Abort(); }
     throw;
   }
}
and the RunService :
Code:

protected void RunService()
{
   sHost = newServiceHost(typeof(wcfBorderauxIRSService.IRSService));
   sHost.Open();
   ServiceEndpoint endpoint = sHost.Description.Endpoints[0];
   EventLog.WriteEntry(endpoint.Contract.Name + " Started" + " listening on " + endpoint.Address + " (" + endpoint.Binding.Name + ")",
System.Diagnostics.EventLogEntryType.Information);
}
then up in my client:

Code:
 
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static String Process(String Irs,String other)
{
..........
   using (IRSService.RSClient WCF = new RSClient())
   {
     WCF.ProcessBorderaux();
   }
.......
Now what happens is the process runs no problem, but i receive a socket time out on the closing } of my using statement in the client. If at this point I stop my client process, the windows/wcf service continues to run, so closing my client browser and stopingthe local web server (running in debug), doesn't kill the server process :). So how do I force the windows service to return as soon as ProcessBorderaux in the WCF Library has been initiated? I was going to do a crafty and say that when it times out I dont care about the error because the batch process has been initiated and is running, but it doesn't matter weather I place a try catch block arounf the Using statement or inside, it doesn't catch the error.

Last edited by Bill Crawley; April 8th, 2011 at 09:12 AM..
 
Old April 11th, 2011, 05:43 AM
Authorized User
 
Join Date: Jun 2003
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, got to the bottom of it. In the client I needed to remove the use of 'Using' the client now doesn't stay attached to the windows service.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Long running package cancelled brendenm BOOK: Microsoft SQL Server 2008 Integration Services Problem-Design-Solution 0 March 7th, 2011 05:24 PM
How to assign a password to an MDF and LDF when attaching and detaching? anil.mahadev2009 SQL Server 2000 1 May 18th, 2009 08:25 AM
get all running processes in all windows OS atingoldy VB How-To 0 June 23rd, 2003 02:28 AM
long running backup schedule prakashvj SQL Server 2000 1 June 9th, 2003 10:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.