[SOLVED] Asynch Wait - form does not update with changes until clicking on the form

Answered
1
0

I call a function using Asynch/Wait that reaches out to another server to get some info. I see in the other server console window that the message gets there and data is sent back.  In my WiseJ application (Desktop Style) – nothing happens – but I noticed that if i do anything on the form – move a window, click anywhere – my form fields update with the returned data.  I tried using   acc_Panel_MetaData.Invalidate(true); to force the panel to refresh but it does not.

I added an alertbox in the function as well. It too does not show until i do something to the form.

When debugging and testing locally with Visual Studio – I did not experience this issue.

I’m using version 1.5.43.0

Any Ideas ?

My function:

 

private async void Lookup(string[] as_valueAry)
{
// Get a reference to the remote Lookup Actor
string ls_RemoteActorSysPath = ConfigurationManager.AppSettings[“ActorSystem.LookupSvc”];
string ls_LookupActorPath = string.Format(“akka.tcp://{0}/user/{1}_IDX{2}”, ls_RemoteActorSysPath,io_User.CompanyId.Trim(),io_IdxInfo.Idx_ID.ToString());
var LookupActor = ImagingActorSystem.AkkaSystem.ActorSelection(ls_LookupActorPath);

LookupAnswerMessage result = await LookupActor.Ask<LookupAnswerMessage>(new LookupMessage(as_valueAry));
AlertBox.Show(“Data Returned” + result.is_lookup_values, MessageBoxIcon.Information, null, System.Drawing.ContentAlignment.MiddleCenter, 5000, null, null);
DataTable lo_Data= io_DataFunctions.StringRowsToDataTable(result.is_lookup_values);
if (lo_Data.Rows.Count > 0)
{
// Populate Metadata
foreach (Control lo_control in acc_Panel_MetaData.Controls)
{
string ls_ControlType = lo_control.GetType().Name.ToString();

if (ls_ControlType.Equals(“ucSearchCriteriaText”, StringComparison.OrdinalIgnoreCase))
{
ucSearchCriteriaText lo_ucSearchCriteriaText = (ucSearchCriteriaText)lo_control;
if (lo_ucSearchCriteriaText.FieldNum > 0 && lo_ucSearchCriteriaText.FieldNum <= lo_Data.Columns.Count)
{
string ls_colName = “value_” + lo_ucSearchCriteriaText.FieldNum;
lo_ucSearchCriteriaText.SetValue(lo_Data.Rows[0][ls_colName].ToString());
}
}

}
}

acc_Panel_MetaData.Invalidate(true);

}

  • You must to post comments
Best Answer
0
0

When your code “awaits” a response from another web server (or another web service, or another thread) it cannot automatically update your client because there is no pending request from the browser and it’s impossible to update the browser without a request from the browser. Unless you push the update using a websocket connection. In Wisej it’s built in so you can call Application.Update() after the await. Unless the await is waiting for a Wisej response (an async dialog or messagebox or javascript call), in which case the update is automatic.

The way async/await works in .NET compilers is to extract the code after the await and compile it into a callback method. The await statement receives a Task instance from the async method, then returns and completes the execution before the await. When the task is completed it calls the callback from the thread that completed the execute in the await. It’s identical to calling a function passing in a callback method.

In alternative you can wait on the task returned by the async method. All async methods return a task:

await Test(); // asyncronous in Wisej

Test().Wait(); // waits for the task to complete, like in ASP.NET

Async programming on a desktop app is easy since you don’t need a request to update the desktop.

Async programming in an ASP.NET app is emulated and in reality it blocks the request. If you try an async event with ASP.NET/MVC or WebAPI you will see that the browser waits for the request to complete synchronously and the ASP.NET session is locked. In fact the calling thread waits on the task.

In Wisej is truly asynchronous. The event is fired and executed on the server asynchronously.

 

  • edmond girardi
    Luca I added: Application.Update(this); At the end of the function after the await call and it worked. Just one question however. should I be using the name of the panel that contain the text boxes to refresh or “this”
  • You must to post comments
0
0

Hi Edmond,

an easy way to see if WebSockets are used is DevTools from Chroms.

See attached image.

Best,

Jens

 

  • You must to post comments
0
0

Yes – server is running websockets. My client machine is Windows 8. Any way to test to see if it’s really being used ?

  • You must to post comments
1
0

Hi Edmond,

is your server running on websockets ?
If not, have you tried calling Application.Update(this) ?

Best regards
Frank

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.