user1438082
user1438082

Reputation: 2748

WCF Function Continue after return

i have a web application that connects to a windows service via WCF and calls a method. After the method has returned its result (and everything is successfull - see line **?? below) i want the service to continue and do some other work.

What is the easiest way to do this?

thanks Damo

C# Code

//Add Files To Control Manager
    public ReturnClass FilesToControl(List<Item> lstNewItems,string ReferenceNumber,string Type,String Description)
   {
       try
       {
           String ThisisAnItemToControl = "";
           String ThisIsItsType = "";

           for (int i = 0; i < lstNewItems.Count; i++) // Loop through List with for
           {
               ThisisAnItemToControl = lstNewItems[i].Paramater;
               ThisIsItsType = lstNewItems[i].Type;

               // Do a pre check on the item

               // Does File Exist

               if (!File.Exists(ThisisAnItemToControl))
                   return new ReturnClass(-1, ThisisAnItemToControl + " does not exist", String.Empty, null, null, null);  



           }

           return new ReturnClass(1, "", String.Empty, null, null, null);


           // Now that we have returned a result to the web application we can get to work and modify the items under control but how can i do this?

         //  **??


       }

       catch (Exception ex)
       {

           return new ReturnClass(-1, ex.Message.ToString(), "", null, null, null);

       }       

Upvotes: 3

Views: 2679

Answers (4)

Science_Fiction
Science_Fiction

Reputation: 3433

Task.Factory.StartNew(() => DoWork());

But one problem you may run into is that you fire off the thread, then IIS kills your WCF service. This is of course assuming your running it in ISS.

Upvotes: 1

Keysharpener
Keysharpener

Reputation: 504

Do the work in another thread or raise an event on the server side, caught by another class/method.

Upvotes: 1

Davin Tryon
Davin Tryon

Reputation: 67296

You could create a new thread as suggested, but if the work that you are doing will be long running, you would be most likely taking threads from the ASP.NET thread pool. This could lead to a degrade in throughput for the application.

So, I would probably have another process, perhaps a windows service, that your WCF application could call to carry out more work. This will decouple the concerns from dealing with the front-facing request, from the background work.

Upvotes: 2

System Down
System Down

Reputation: 6270

What I would do is place the extra work in another function. Then, just before you return from the WCF function, create a new thread for the extra work function and run it.

Upvotes: 3

Related Questions