1 Replies - 1934 Views - Last Post: 25 July 2015 - 11:49 AM Rate Topic: -----

#1 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5890
  • View blog
  • Posts: 20,104
  • Joined: 05-May 12

Exceptions and flow control...

Posted 22 July 2015 - 07:34 AM

It is irony or coincidence that on the same day this post entitled C++ Vs C# On Exceptions comes along, I discover that I've inherited the following ASP.NET C# code:
        public void BackgroundService()
        {
            try
            {
                ThreadStart action = () =>
                {
                    try
                    {
                        while(true)
                        {
                            DoSomeTimeConsumingWorkToSimulateBusinessConnectivityServicesForSharePoint();
                            Thread.Sleep(2500);
                        }                        
                    }
                    catch(Exception e)
                    {
                        BackgroundService();
                    }
                };
                Thread thread = new Thread(action) { IsBackground = true, Priority = ThreadPriority.Lowest };
                thread.Start();
            }
            catch (Exception e)
            {
            }
        }



Note lines 14-17.

On top of the incorrect use of exceptions, this code does a recurring background task in ASP.NET. It does nothing to protect itself. See The Dangers of Implementing Recurring Background Tasks In ASP.NET

Is This A Good Question/Topic? 1
  • +

Replies To: Exceptions and flow control...

#2 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1571
  • View blog
  • Posts: 3,529
  • Joined: 05-April 11

Re: Exceptions and flow control...

Posted 25 July 2015 - 11:49 AM

Thanks for the link, gave some good insight
Now I'm just sitting here wondering what might happen with websocket connections? But I'm not working with ASP.NET at the moment, so I shouldn't be worried :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1