none
CacheItemRemovedCallback fires twice RRS feed

  • Question

  • I'm using the CacheItemRemovedCallback on a system.web.caching.cache object to schedule some work though I'm having problems with the callback being called twice and I can't find any resolutions.

    Why is vb.net calling the callback twice and therefore running my code twice? It's causing double entries in my database!

    Friday, June 8, 2012 4:42 PM

Answers

  • I think I just realised what it is! It's because it's a Windows Azure project and I have two role instances so the two separate roles are firing at the same time. Doh!

    There must be a better/safer way to schedule regular work in an asp.net web application. I will keep digging.

    Friday, June 8, 2012 8:03 PM

All replies

  • th eeasiest way of finding the problem is to put a break point on the line and stop the second time you reak the break point.  Then look at the call stack

    Debug - window - Callstack

    Yo can click on each line of the call stack and it will open the line where a call was made to another function.  some cases multiple call are normal.  for example when you perform a copy and paste on an excel worksheet you will get a change event for each cell that get modified.  In excel programming, you often disable event from occuring inside event handlers so you don't tricker multiple occurances of the same event.


    jdweng

    Friday, June 8, 2012 4:49 PM
  • All I get is a single line in the call stack and it doesn't seem to have any helpful information..?
    Friday, June 8, 2012 5:17 PM
  • Is the line always the same line?  At least your know which line(s) of code is causing the causing both of the the callbacks.


    jdweng

    Friday, June 8, 2012 5:33 PM
  • I think I just realised what it is! It's because it's a Windows Azure project and I have two role instances so the two separate roles are firing at the same time. Doh!

    There must be a better/safer way to schedule regular work in an asp.net web application. I will keep digging.

    Friday, June 8, 2012 8:03 PM