locked
How to stop LINQ query execution RRS feed

  • Question

  • Hi,

    I am developing a application and i make a function say A();.From this function i execute a LINQ search query.When the number of records is large enough the query takes longer time.At that time i want to logout from application but the logout event remains in queue.Is there is any solution to tackle with this problem.

    Monday, September 9, 2013 10:02 AM

All replies

  • Hello,

    Thanks for visiting MSDN forum.

    About how to stop LINQ query execution, as far as I know, we can try it with solution like below:

    var arrayOfInt = new int[] {1,2,3,4,5};
    Func<bool, int> checkCancel = (val) => {
      if(val == 3) throw new Exception("Linq query is interrupted!");
      return true;
    };
    try{
      var results = from val in arrayOfInt
        where checkCancel(val)
        select result;
    } catch {
      //query was interrupted
    }

    You can change the checkCancel(val) to fit it to your program like count>100000 or time > 10minutes.

    Best Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, September 10, 2013 3:16 AM