这是服务器端的示例
* : *
public void AsyncWork()
{
// start working in a new thread
var task = Task.Factory.StartNew(() => dosomething());
task.ContinueWith(t =>
{
Caller.notifyResult(t.Result);
});
}
private int dosomething()
{
int result =0;
return result;
}
在客户端:
<script type="text/javascript">
// init hub
var proxy = $.connection.signals;
// declare response handler functions, the server calls these
proxy.notifyResult = function (result) {
alert("the result was: " + result);
};
// start the connection
$.connection.hub.start();
// Function for the client to call
function AsyncWork() {
proxy.AsyncWork();
}
</script>