Asynchronous callback difference Smobiler with Windows

Asynchronous callback difference Smobiler with Windows - based development APP difference between .NET and Windows development

APP development based on Windows and .NET development, asynchronous callback difference

Windows app developers asynchronous callback Smobiler example

In the development Smobiler, the client controls or components and functions are to be handled by an event or delegate.

Smobiler is based on asynchronous non-blocking way to run the

Here we were on the Windows MessageBox and treatment of Smobiler to illustrate.

Windows MessageBox method of

l developed over the MessageBox Windows are familiar, selected values ​​can be determined directly behind MessageBox.Show and subsequent processing, the following code

if (System.Windows.Forms.MessageBox.Show("MessageBox", "Yes/No", MessageBoxButtons.YesNo) == DialogResult.Yes)

{

}

MessageBox.Show("After MessageBox");

l above code will first pop up on the computer the MessageBox, after click or not, will then pop After MessageBox, following FIG.

clip_image002

Smobiler method of MessageBox

However, in the Smobiler l, MessageBox.Show method is void, that is not on behalf of the return value. So how to get the selected value of MessageBox it? We look at the following code.

MessageBox.Show ( "Asynchronous illustrative example," "is displayed and a dialog NO", MessageBoxButtons.YesNo);

Toast ( "client clicks that result?");

L After the above code to open Smobiler client connections and testing, you will find, "explained asynchronous example," the dialog box that appears at the same time, there will be a "result of client clicked?" Prompt. The following display.

Winform dialog with the difference Smobiler

l Why is this? We will explain below

n Windows code to run on the Windows operating system, is a stand-alone, it is based on the UI thread blocking, when prompted, when you do not click on the interface, it is currently the UI thread is in a wait state until you clicking on the prompt box interface, this thread would be restored, and only then the code behind then executed. As exemplified in FIG.

clip_image004

n Smobiler respectively, the client and the server, the client needs to display MessageBox, you need to tell the client to be displayed, the user clicks and then send the click event on the client to the server on the server, the server calls the code, in fact, also Smobiler can be made into thread blocking the way, but Smobiler server not only as a Windows desktop application UI thread, it also contains all of the client, if the UI thread is blocked, then each client needs to have a blocking thread this (has been in a wait state that is necessary to maintain the server threads) running Smobiler server can cause significant performance issues. So Smobiler early in the design, use asynchronous non-blocking manner.

Smobiler asynchronous non-blocking

l be optimized based on the above code, it first ejected in SmoMessageBox, after the completion of the pop-up and select After MessageBox, dynamic effects such as the following FIG.

MessageBox.Show ( "Asynchronous illustrative example," "is displayed and a dialog NO", MessageBoxButtons.YesNo, (obj, args) =>

{

Toast ( "client clicks result is" + args.Result.ToString ());

});

Toast ( "this and dialog boxes are displayed at the same time");

clip_image006

l You will find Smobiler final surface MessageBox.Show is an anonymous method (which is a delegate instance, if entrusted do not understand you can first add knowledge in this area), which is an asynchronous callback that the client user click SmoMessageBox, subsequent operations to be triggered, you need to write to the anonymous method (also can be a delegate instance). As shown below.

clip_image008

l In many functions Smobiler the need to use this approach, such as this.Client.GetClipboard get clipboard data, we need to get the current data in the callback. This.Client.GetNetWorkType type or the like to obtain network.

Guess you like

Origin blog.51cto.com/14360220/2404630