Asp.net with Muhanad YOUNIS

What if you like to call a web service and retry the call again until response? let me show you a nice way to call a function with retry until you retrieve what ever is needed from the function. This could be achieved by using generics especially by extending the Func<T> delegate; check the code below;

1:publicstaticclass MyExtensions

2: {

3:publicstatic T WithRetry<T>(this Func<T> action)

4: {

5: var result = default(T);

6:int retryCount = 0;

7: var succesful = false;

8:do

9: {

10:try

11: {

12: result = action();

13: succesful = true;

14: }

15:catch (Exception ex)

16: {

17: retryCount++;

18: }

19: } while (retryCount < 3 && !succesful);

20:return result;

21: }

22: }

In the code you can see that we extended the Func that will return an object with type T. This function will keep trying for 3 times but you might change it to keep it trying until it achieve the goal. and here is how to use it

Here in this post I’ll show you how you to count online users while using state server or SQL server for session state. When you use state server you are not able to catch the session_end event on the global.asax, there for you may not be able to drop the user from you count!. I’ll show you a way to count users. the tutorial will be split into 3 parts;

Yesterday one of our project team member faced a challenge of using an anonymous data that is returned from joining 2 typed data tables with LINQ. The problem is not how to use the data, the problem was how to be able to cast and use the data in Repeater ItemDataBond method without having “<>f__AnonymousType0….” cast error. below is the join query (tables used are typed) :-