c# - Is the callBack method called before the assignment or after here? -


i have code below calling domain service in silverlight application.

loadoperation<tcity> loadoperation = _datacontext.load(query,callback, true); 

can tell me operation done first?

is callback method called before loadoperation variable assigned or after assigned?

thanks

assuming it's meant asynchronous operation, happen either way, in theory. asynchronous operation should occur in thread, , if finishes before load returns, callback called before assignment completes.

in practice, i'd expect async call take much longer whatever housekeeping load @ end of method - wouldn't put assumption code. unless there's explicit synchronization ensure assignment occurs before callback, don't think it's idea rely on it.

even if @ moment assignment happens first, consider:

  • what happens if there's no network connection @ moment? async call fail quickly.
  • what happens if caching added client-side? call succeed quickly.
  • i don't know kind of testing you're able against ria services, may want able mock asynchronous calls making them execute callback on same thread - means callback could happen in tests before assignment. avoid forcing genuinely asynchronous mock call, handling threading in tests can hairy; it's easiest make synchronous.

edit: i've been thinking more, , trying work out reasons behind gut feeling shouldn't make assumption, though it's going fine in reality.

relying on order of operations against spirit of asynchronicity.

you should (imo) setting off, , ready come @ time. that's how should thinking it. once start down slippery slope of "i'm sure i'll able little bit of work before response returned" end in world of uncertainty.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -