none
How to stop long running call back from Client? RRS feed

  • Question

  • I am using a wcf service. In which a server function  Process on some collection of  items and Updating the Ui in the client side.  if the request contains  'N" number of items then it process each item and update the client Ui by 'N' times calling back. Now it need to stop the before 'N' times. How it can be achieved? pls help me.
    Monday, July 15, 2013 2:09 PM

Answers

  • Could you elaborate more on your problem and what you're actually trying to accomplish. Your description is a bit vague. From what I've gathered I assume you want to be able to have the client inform the server that it wishes to cancel some processing that the server is doing on its behalf. Is that correct? If so you can expose an addition method in your contract that the client can call, this method will set a flag that the operation that you wish to cancel checks after each iteration of its processing.

    private bool cancelFlag;
    
    // processing method
    void Process()
    {
        foreach (var item in itemCollection)
        {
            if (cancelFlag) break;
            
            // your processing code
            ...
        }
    }
    
    void Cancel()
    {
        cancelFlag = true;
    }

    Of course the code above is overly simplified. The actual code would need to take into account the fact that you may have multiple Process operations simultaneously so you'll identify the one that needs to be cancelled etc.
    Monday, July 15, 2013 2:26 PM