code_junkie

Does This ASP.NET Consultant Know What He's Doing?

Nov 11th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. void MyFunction()
  2. {
  3. Session["UserID"] = SomeProprietarySessionManagementLookup();
  4. Response.Redirect("SomeOtherPage.aspx");
  5. }
  6.  
  7. int MyFunction(int x, int x)
  8. {
  9. try
  10. {
  11. return x / y;
  12. }
  13. catch(Exception ex)
  14. {
  15. // log it
  16. throw;
  17. }
  18. }
  19.  
  20. int MyFunction(int x, int y, out bool isSuccessful)
  21. {
  22. isSuccessful = false;
  23.  
  24. if (y == 0)
  25. return 0;
  26.  
  27. isSuccessful = true;
  28.  
  29. return x / y;
  30. }
  31.  
  32. int MyFunction(int x, int y)
  33. {
  34. if (y == 0)
  35. {
  36. // log it
  37. throw new DivideByZeroException("Divide by zero attempted!");
  38. }
  39.  
  40. return x / y;
  41. }
  42.  
  43. Session["UserID"] = SomeProprietarySessionManagementLookup();
  44.  
  45. public void SomeProprietarySessionManagementLookup()
  46. {
  47. // do some async lookup
  48. Action<object> d = delegate(object val)
  49. {
  50. LookupSession(); // long running thing that looks up the user.
  51. Session["UserID"] = 1234; // Setting session manually
  52. };
  53.  
  54. d.BeginInvoke(null,null,null);
  55. }
  56.  
  57. Action<object> d = delegate(object val)
  58. {
  59. System.Threading.Thread.Sleep(1000); // waits a little
  60. Session["rubbish"] = DateTime.Now;
  61. };
  62.  
  63. d.BeginInvoke(null, null, null);
  64. System.Threading.Thread.Sleep(5000); // waits a lot
  65.  
  66. object stuff = Session["rubbish"];
  67. if( stuff == null ) stuff = "not there";
  68. divStuff.InnerHtml = Convert.ToString(stuff);
  69.  
  70. Action<object> d = delegate(object val)
  71. {
  72. System.Threading.Thread.Sleep(5000); // waits a lot
  73. Session["rubbish"] = DateTime.Now;
  74. };
  75.  
  76. d.BeginInvoke(null, null, null);
  77.  
  78. // wait removed - ends immediately.
  79. object stuff = Session["rubbish"];
  80. if( stuff == null ) stuff = "not there";
  81. divStuff.InnerHtml = Convert.ToString(stuff);
  82.  
  83. Session["UserID"] = SomeProprietarySessionManagementLookup();
  84.  
  85. SomeProprietarySessionManagementLookup(Session["UserID"]);
Add Comment
Please, Sign In to add comment