Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Windows Service shutting down

C# Windows Service shutting down

Scheduled Pinned Locked Moved C#
csharphelpsysadmin
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saamir
    wrote on last edited by
    #1

    Hi Guys, I need some help please. I have the following code being called in my timer_elapsed function and my timer is being enabled in the onstart of the windows service. This worked fine with .net 1.1 but ever since I have converted the application to .net 2.0, my service shuts down without notice when there is trafic in client requests i.e. ProcessClientRequest call. When I try to restart the service upon shut down it gives me an error saying "Only one usage of each socket address (protocol/network address/port) is normally permitted" So I have to stop and wait a few and restart and it works fine and then again when there is much activity in processclientrequest call it shuts down. I know this is not much information but please help me if you have any ideas. Writ2ErrLog("Service Timer Initialized"); string sErr = "Application is ready for processing"; try { Writ2ErrLog(sErr); m_tMonitor = new TD.Timer(new TD.TimerCallback(MonitorFunc), 1, 0, 45000);//45 sec if (m_sServerAddr == string.Empty) { m_sServerAddr = Dns.GetHostName(); } if (m_nPort == -1) { m_nPort = 1024; } IPHostEntry hostEntry = Dns.GetHostEntry(m_sServerAddr); IPAddress ipAddress = hostEntry.AddressList[0]; IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, m_nPort); m_svSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_svSocket.Bind(ipEndPoint); m_svSocket.Listen(10); while (true) { try { Socket rtSocket = m_svSocket.Accept(); if (rtSocket.Connected) { TD.WaitCallback myCallBack = new TD.WaitCallback(ProcessClientRequest); TD.ThreadPool.QueueUserWorkItem(myCallBack, rtSocket); } } catch (Exception ex) { Writ2ErrLog(ex.Message); break; } } } catch (Exception ex) { m_svSocket.Close(); m_tMonitor.Dispose(); sErr = "

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups