Anurag Malani

Anurag Malani

  • NA
  • 80
  • 34.4k

The array bounds are invalid in c# windows service

Nov 11 2013 2:40 AM
Hi,

I have a problem  on C# windows service, its showing an error - The array bounds are invalid

Note - If my dv.Count value is less than or equal to 1000 then its not showing error and works fine, but id  dv.Count is more then 1000 then it generate the error....

Here is my code

  string[] arg = new string[dv.Count];
  for (int xx = 0; xx < dv.Count; xx++)
  {
  arg[xx] = dv[xx]["id"].ToString() + "," + dv[xx]["item"].ToString()
  }

    ServiceController sc = new ServiceController("Service1");
  if (sc != null)
  {
  if (sc.Status.ToString().ToLower() == "stopped")
  {
  sc.Start(arg); // Error Occurred Here
  }
  }


Here is the full  error details.

System.InvalidOperationException: Cannot start service xxxxx on computer '.'. ---> System.ComponentModel.Win32Exception: The array bounds are invalid
  --- End of inner exception stack trace ---
  at System.ServiceProcess.ServiceController.Start(String[] args)
  at xxxxxx.Service1.Generate(Object sender, ElapsedEventArgs e)



Can someone please help on this...?



Answers (1)