Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Handling multiple heavy data query using Multiple Theadpool threading

$
0
0

I have an application getting the location of the user. The logic is if the device is connected to the any provider he will send the data to the server Else if the device is not connected to the provider he will save it to the db. +++This is the Problem++ 1.If i query more data from db even i make some thread for it sometimes i got a force close issue. this is my code --

first i made a thread for sending data to server

     new Thread(new ThreadStart(() =>
                        {


                            while (y < 10000)
                            {
                                Thread.Sleep(10000);
                                RunOnUiThread(() => getloc()); 
                            }
                        })).Start();



                }

this the code for the getloc function

      public void getloc()
            {
                    ConnectivityManager cm = (ConnectivityManager)this.GetSystemService(Context.ConnectivityService);
                    NetworkInfo nf = cm.ActiveNetworkInfo;
                    if (nf != null && nf.IsConnected == true)
                    {
                        if (latText.Text != "" && longText.Text != "")
                        {

                          //i omit my code here

                           if (DBMain.getStatus() == "unsend")
                            {

                                loginWithThreadPool();
                            }

                        }

            }   

In if (DBMain.getStatus() == "unsend") if there is data here he will he will execute the loginWithThreadpool

 private void loginWithThreadPool()
     {

         ThreadPool.QueueUserWorkItem(state =>
         {
           getStatus(); 
         });
     }
 public  void getStatus()
        {
            string query = "SELECT lat,long,imei,times,altitude,speed,bear,accu,ID from tbltracks where status = 'unsend' ORDER BY ID ASC";
            string dbPath = Android.OS.Environment.ExternalStorageDirectory + "/DB/TRACKER";
            var connection = new SqliteConnection("Data Source=" + dbPath);
            connection.Open();
            using (var contents = connection.CreateCommand())
            {
                contents.CommandText = query;
                var r = contents.ExecuteReader();
                while (r.Read())
                {


                    lat1 = r[0].ToString();
                    long1 = r[1].ToString();

                     ThreadPool.QueueUserWorkItem(state =>  forUnsentData());

                    }

                }

                contents.Dispose();
            }




            connection.Close();
            connection.Dispose();


        }

What is the consequence in using multiple threadpool in android? sorry guys for the long story i want to make it clear


Viewing all articles
Browse latest Browse all 204402

Trending Articles