Click here to Skip to main content
15,881,044 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an application that takes picture of a map.
when im going to download the images I receive Invalid operation exception

What I have tried:

private bool GetRequestsAndDownload()
       {
           coordinatesConverter = new CoordinatesConverter();

           decimal dcLength = 0;
           decimal dcWidth = 0;
           string strTopLeft = string.Empty;
           string strBottomRight = string.Empty;
           string strX1 = string.Empty;
           string strY1 = string.Empty;
           string strX2 = string.Empty;
           string strY2 = string.Empty;
           double dblTotalWidth = 0;
           double dblTotalLength = 0;
           double dblOverlapRatio = 1;

           try
           {
               DataTable dtRequests = new DataTable();

               if (!mapNRPSinarpimGoogleMapDownloader.ReqListInfo_DownloadRequestScales(dtRequests))
               {
                   mapNRPSinarpimGoogleMapDownloader.RegisterErrorLog("Error in private void GetRequestsAndDownload() IN ReqListInfo_DownloadRequestScales , Description: " + mapNRPSinarpimGoogleMapDownloader.ErrMessage);
                   return false;
               }
               foreach (DataRow drRequest in dtRequests.Rows)
               {
                   strTopLeft = coordinatesConverter.ConvertGeoToLambert(drRequest["X_Top"].ToString(), drRequest["Y_Left"].ToString());
                   strBottomRight = coordinatesConverter.ConvertGeoToLambert(drRequest["X_Bottom"].ToString(), drRequest["Y_Right"].ToString());
                   strX1 = strTopLeft.Split('^')[0];
                   strY1 = strTopLeft.Split('^')[1];
                   strX2 = strBottomRight.Split('^')[0];
                   strY2 = strBottomRight.Split('^')[1];
                   dblTotalLength = double.Parse(strX2) - double.Parse(strX1);
                   dblTotalWidth = double.Parse(strY1) - double.Parse(strY2);

                   switch (drRequest["Zoom"].ToString())
                   {
                       case "4":
                           dcLength = int.Parse(Math.Floor(7725587.947 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(6234225.796d * dblOverlapRatio).ToString());
                           break;
                       case "5":
                           dcLength = int.Parse(Math.Floor(4015073.66 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(4089905.38 * dblOverlapRatio).ToString());
                           break;
                       case "6":
                           dcLength = int.Parse(Math.Floor(1974448.305 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(2077535.6 * dblOverlapRatio).ToString());
                           break;
                       case "7":
                           dcLength = int.Parse(Math.Floor(993268.35 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(1033088.65 * dblOverlapRatio).ToString());
                           break;
                       case "8":
                           dcLength = int.Parse(Math.Floor(495397.724 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(517838.934 * dblOverlapRatio).ToString());
                           break;
                       case "9":
                           dcLength = int.Parse(Math.Floor(248062.84 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(258524.517 * dblOverlapRatio).ToString());
                           break;
                       case "10":
                           dcLength = int.Parse(Math.Floor(123788.82 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(129494.81 * dblOverlapRatio).ToString());
                           break;
                       case "11":
                           dcLength = int.Parse(Math.Floor(61819.8 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(64818.66 * dblOverlapRatio).ToString());
                           break;
                       case "12":
                           dcLength = int.Parse(Math.Floor(30960.08 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(32361.398 * dblOverlapRatio).ToString());
                           break;
                       case "14":
                           dcLength = int.Parse(Math.Floor(15479.217 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(16181.49 * dblOverlapRatio).ToString());
                           break;
                       case "15":
                           dcLength = int.Parse(Math.Floor(7758.55 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(8072.57 * dblOverlapRatio).ToString());
                           break;
                       case "16":
                           dcLength = int.Parse(Math.Floor(3866.77 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(4048.26 * dblOverlapRatio).ToString());
                           //dcLength = int.Parse(Math.Floor(1500 * dblOverlapRatio).ToString());
                           //dcWidth = int.Parse(Math.Floor(1500 * dblOverlapRatio).ToString());
                           break;
                       case "17":
                           dcLength = int.Parse(Math.Floor(1932.17 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(2025.28 * dblOverlapRatio).ToString());
                           break;
                       case "18":
                           dcLength = int.Parse(Math.Floor(971.93 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(1007.03 * dblOverlapRatio).ToString());
                           break;
                       case "19":
                           dcLength = int.Parse(Math.Floor(484.21 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(505.2 * dblOverlapRatio).ToString());
                           break;
                       case "20":
                           dcLength = int.Parse(Math.Floor(241.63 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(253.05 * dblOverlapRatio).ToString());
                           break;
                       case "21":
                           dcLength = int.Parse(Math.Floor(121.02 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(126.33 * dblOverlapRatio).ToString());
                           break;
                       case "22":
                           dcLength = int.Parse(Math.Floor(60.49 * dblOverlapRatio).ToString());
                           dcWidth = int.Parse(Math.Floor(63.18 * dblOverlapRatio).ToString());
                           break;
                       default:
                           //err log
                           break;
                   }

                   int intTotalI = int.Parse(Math.Floor(dblTotalLength / double.Parse(dcLength.ToString())).ToString());
                   int intTotalJ = Math.Abs(int.Parse(Math.Floor(dblTotalWidth / double.Parse(dcWidth.ToString())).ToString()));

                   decimal dcBase_X = decimal.Parse(strX1);
                   decimal dcBase_Y = decimal.Parse(strY1);

                   decimal dcX1 = decimal.Parse(strX1);
                   decimal dcX2 = decimal.Parse(strX2);
                   decimal dcY1 = decimal.Parse(strY1);
                   decimal dcY2 = decimal.Parse(strY2);
                   decimal dcXCenter = 0;
                   decimal dcYCenter = 0;
                   string strCenterPoint = string.Empty;

                   for (int j = 0; j < intTotalJ; j++)
                   {
                       dcX1 = dcBase_X;
                       dcY1 = dcBase_Y;
                       decimal dcFactor = (decimal)0.1;

                       for (int i = 0; i < intTotalI; i++)
                       {
                           //dcX1 = dcX1 + (i * dcWidth);
                           ////dcX1 = (dcX1 - (int)(dcWidth * dcFactor)) + (i * (dcWidth * ((decimal)1.2)));
                           //dcX2 = dcX1 + dcWidth;
                           ////dcX2 = dcX1 + (dcWidth * ((decimal)1.2));

                           //dcY1 = dcY1 - (j * dcLength);
                           //dcY2 = dcY1 - dcLength;

                           dcX1 = dcBase_X + (i * dcWidth);
                           dcX2 = dcX1 + dcWidth;

                           dcY1 = dcBase_Y - (j * dcLength);
                           dcY2 = dcY1 - dcLength;

                           dcXCenter = (dcX1 + dcX2) / 2;
                           dcYCenter = (dcY1 + dcY2) / 2;

                           strCenterPoint = coordinatesConverter.LambertToGeo(double.Parse(dcXCenter.ToString()), double.Parse(dcYCenter.ToString()));

                           new Thread(delegate()
                           {
                               CallShowMap(MapType.MapTypeHybridSatellite, Convert.ToDouble(strCenterPoint.Split('^')[0]), Convert.ToDouble(strCenterPoint.Split('^')[1]), Convert.ToDouble(drRequest["Zoom"].ToString()), i, j);
                               //CallShowMap(MapType.MapTypeHybridSatellite, Convert.ToDouble(strCenterPoint.Split('^')[1]), Convert.ToDouble(strCenterPoint.Split('^')[0]), Convert.ToDouble(drRequest["Zoom"].ToString()), i, j);
                           }).Start();
                           //SendOrPostCallback invoker = new SendOrPostCallback(
                           //    delegate(object data)
                           //    {
                           //        CallShowMap(MapType.MapTypeHybridSatellite, Convert.ToDouble(strCenterPoint.Split('^')[0]), Convert.ToDouble(strCenterPoint.Split('^')[1]), Convert.ToDouble(drRequest["Zoom"].ToString()), i, j);
                           //    });
                           //MethodInvoker mi = delegate
                           //{
                           //    CallShowMap(MapType.MapTypeHybridSatellite, Convert.ToDouble(strCenterPoint.Split('^')[0]), Convert.ToDouble(strCenterPoint.Split('^')[1]), Convert.ToDouble(drRequest["Zoom"].ToString()), i, j);

                           //};

                       }
                   }
                 //  return true;
                   //double Xc = (double.Parse(x1) + double.Parse(x2)) / 2;
                   //double Yc = (double.Parse(y1) + double.Parse(y2)) / 2;
                   //coordinatesConverter.LambertToGeo(double.Parse(x1), double.Parse(y1));
                   //coordinatesConverter.LambertToGeo(double.Parse(x2), double.Parse(y2));
               }
           }
           catch (Exception)
           {

               return false;
           }
           return true;
       }

public void ControlThreadProc()
       {
           while (m_bRunning == true)
           {
               // Check threads execution
               bool bRestart_0 = false;
               bool bRestart_1 = false;
               bool bRestart_2 = false;
               bool bRestart_3 = false;
               bool bDownloadFinished = true;
               foreach (DownloadInfo di in m_DownloadQue)
               {
                   if (di.bComplete == false)
                   {
                       bDownloadFinished = false;
                       TimeSpan ts = DateTime.Now.Subtract(di.time);
                       if (ts.Seconds > 10)
                       {
                           if (di.serverId == 0)
                           {
                               bRestart_0 = true;
                           }
                           if (di.serverId == 1)
                           {
                               bRestart_1 = true;
                           }
                           if (di.serverId == 2)
                           {
                               bRestart_2 = true;
                           }
                           if (di.serverId == 3)
                           {
                               bRestart_3 = true;
                           }
                       }
                   }
               }
Posted
Comments
Eric Lynch 21-Jul-18 3:38am    
Too much code to weed through...step through the debugger...find the line where the exception is thrown and excerpt it. Also, if you can, include the stack trace (exception.ToString()) for the exception. Sometimes there are inner exceptions which provide additional detail.
Richard MacCutchan 21-Jul-18 5:18am    
int intTotalI = int.Parse(Math.Floor(dblTotalLength / double.Parse(dcLength.ToString())).ToString());

Why on earth are you converting values to strings, just so you can parse them back to their original values? Just use simple maths:
int intTotalI = int(Math.Floor(dblTotalLength / dcLength));

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900