Many other methods in web service are used throughout the app and work just fine. Only one method in particular is giving trouble. When the method is invoked directly from browser, result is pretty instantaneous, so the web service itself seems to be fine. But when a breakpoint is placed on the line where the service is consumed for this particular method, everything freezes for about 1.5 to 2 minutes. Switched to async version of method and stopped the app from freezing, but the results of the method are not in the SQL database for the same 1.5 to 2 minutes. This method worked just fine up until a couple days ago and then suddenly started behaving this way.
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == Result.Ok && requestCode == 0)
{
var settings = PreferenceManager.GetDefaultSharedPreferences(this);
var assetID = settings.GetString("unit", null);
var sender = settings.GetString("sender", null);
var conn = inst2.conn();
var c = conn.CreateCommand();
c.CommandText = "Select Contract From CurrentContract";
var transID = 0;
try
{
conn.Open();
SqliteDataReader dr = c.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
transID = Convert.ToInt32(dr[0].ToString());
}
dr.Close();
conn.Close();
}
catch (System.Exception ex)
{
conn.Close();
Dialog d = inst2.showBuilder(this, "Error", ex.Message);
d.Show();
}
TableLayout tl = (TableLayout)FindViewById(Resource.Id.myEquip);
View v1 = tl.FindViewWithTag(sender);
Button bt = (Button)v1;
Bitmap bitmap = (Android.Graphics.Bitmap)data.Extras.Get("data");
string base64String = "";
using (var stream = new System.IO.MemoryStream())
{
bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 0, stream);
byte[] imageBytes = stream.ToArray();
base64String = Convert.ToBase64String(imageBytes);
}
try
{
//This is where it gets stuck
inst.saveImage(base64String, assetID, transID);
bt.Visibility = ViewStates.Invisible;
conn.Open();
c.CommandText = "Drop Table If Exists CurrentContract";
c.ExecuteNonQuery();
conn.Close();
}
catch (System.Exception ex)
{
conn.Close();
Dialog d = inst2.showBuilder(this, "Error", ex.Message);
d.Show();
}
}
}
inst.saveImage is a void that runs a SQL stored procedure that simply updates the line of the contract with the base64 encoded string containing values from the camera intent.
[WebMethod]
public void saveImage(string stream, string assetID, int transID)
{
var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
var comm = new SqlCommand("saveContractImage", conn);
comm.CommandType = System.Data.CommandType.StoredProcedure;
comm.Parameters.AddWithValue("@AssetID", assetID);
comm.Parameters.AddWithValue("@TransID", transID);
comm.Parameters.AddWithValue("@Bytes", stream);
try
{
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
conn.Close();
throw (ex);
}
}
I think this may have been device specific. Have used on other devices since and seems to work ok.