在WPF应用程序中运行WCF侦听器(Running a WCF listener in a WPF application)
我们希望能够从服务器与WPF应用程序通信。
是否可以在WPF应用程序中拥有WCF侦听器/服务? 然后调用此服务在WPF应用程序中打开一个屏幕?
We would like to be able to communicate with a WPF application from the server.
Is it possible to have a WCF listener / service in a WPF application? And then call this service to open a screen in the WPF application?
原文:https://stackoverflow.com/questions/6173671
最满意答案
clearInterval
不接受第二个参数。并且setTimeout更容易包裹...一个简单的方法是计算到目前为止你创建了多少敌人,并且在达到限制时不运行
setTimeout
:var initEnemies = function () { var numEnemiesCreated = 0; function createAnotherEnemy() { var randomX = Math.floor(Math.random() * 190); var randomY = Math.floor(Math.random() * 50); enemy.push(new Enemy(randomX, randomY).create()); numEnemiesCreated += 1; if (numEnemiesCreated < 10) setTimeout(createAnotherEnemy, 1000); } createAnotherEnemy(); }
还有一个带有for循环的版本,它从现在起调度函数调用0s,1s,2s,...,9s:
var initEnemies = function () { function createEnemy() { var randomX = Math.floor(Math.random() * 190); var randomY = Math.floor(Math.random() * 50); enemy.push(new Enemy(randomX, randomY).create()); } for (var i=0; i < 10; i++) setTimeout(createEnemy, i * 1000); }
更新
这是一个带有
setInterval
和clearInterval
的版本。 您仍需要计算到目前为止已创建的敌人数量,并且必须在clearInterval
调用中使用间隔ID。 没试过这个,对不起!var initEnemies = function () { var numEnemiesCreated = 0; var intervalId; function createEnemy() { var randomX = Math.floor(Math.random() * 190); var randomY = Math.floor(Math.random() * 50); enemy.push(new Enemy(randomX, randomY).create()); // Unschedule ourselves after 10th run numEnemiesCreated += 1; if (numEnemiesCreated == 10) clearInterval(intervalId); } intervalId = setInterval(createEnemy, 1000); }
clearInterval
doesn't take second argument.And setTimeout is easier to wrap head around... A simple approach is to count how many enemies you've created so far and not run
setTimeout
when the limit is reached:var initEnemies = function () { var numEnemiesCreated = 0; function createAnotherEnemy() { var randomX = Math.floor(Math.random() * 190); var randomY = Math.floor(Math.random() * 50); enemy.push(new Enemy(randomX, randomY).create()); numEnemiesCreated += 1; if (numEnemiesCreated < 10) setTimeout(createAnotherEnemy, 1000); } createAnotherEnemy(); }
And a version with for loop, it schedules function calls 0s, 1s, 2s, ... , 9s from now:
var initEnemies = function () { function createEnemy() { var randomX = Math.floor(Math.random() * 190); var randomY = Math.floor(Math.random() * 50); enemy.push(new Enemy(randomX, randomY).create()); } for (var i=0; i < 10; i++) setTimeout(createEnemy, i * 1000); }
update
Here's a version with
setInterval
andclearInterval
. You still have to count how many enemies you've created so far, and you have to use interval id inclearInterval
call. Haven't tested this, sorry!var initEnemies = function () { var numEnemiesCreated = 0; var intervalId; function createEnemy() { var randomX = Math.floor(Math.random() * 190); var randomY = Math.floor(Math.random() * 50); enemy.push(new Enemy(randomX, randomY).create()); // Unschedule ourselves after 10th run numEnemiesCreated += 1; if (numEnemiesCreated == 10) clearInterval(intervalId); } intervalId = setInterval(createEnemy, 1000); }
相关问答
更多-
答案是因为我把东西放在了SFXML和普通scalaFX的中间 我发现的第一件事是import scalafx.Includes._这是我在示例中设法忽略的一行是一条“魔术线”,它修复了javaFX和scalaFX之间的所有奇怪现象。 这修复了scene = new Scene(root)的No constructor错误 我在我的控制器类上有一个@sfxml注释,但是没有使用SFXML的FXMLView加载它,这导致javafx无法找到no args构造函数。 最后FXMLView需要一个Dependenc ...
-
clearInterval不起作用(clearInterval not working)[2022-03-06]
我认为Transition事件没有被触发,但是adapt事件被一次又一次触发。 因此, resizeTime更改之前活动之一被清除。 您可以通过在设置新间隔之前清除间隔来修复它(至少使它更好)。 clearInterval(resizeTime); resizeTime = setInterval(function(){ console.log('go', resizeTime); methods.relayoutChildren.ap ... -
所以目前,你的代码将运行类似这样的顺序: window.intervalcount = 0; // Interval is defined here var interval = setInterval(function () { intervalcount += 1; $("#feedback").text(intervalcount); }, 1000); // will be 0 still if(intervalcount > 5) { clearInterval(int ...
-
%d代表数字。 StrRule显然不是一个数字。 你打算用%s吗? RegelText应该是这样的: "RegelText" = "You lose %s goals if you miss."; 或者只使用Rule而不是将其转换为字符串。 代码可能是这样的: Rule = Level / 10 let RegelString = String(format: NSLocalizedString("RegelText", comment: ""), Rule) 在这种情况下, RegelText仍将使用 ...
-
我认为问题不在于间隔,试试 var move_right; function movimento_avanti($el) { $el.find('a img').stop(true).animate({ 'margin-left': '4px', 'margin-right': '0' }, 500, function() { if ($el.data('hovered')) { movimento_indietro($el); } ...
-
clearInterval不接受第二个参数。 并且setTimeout更容易包裹...一个简单的方法是计算到目前为止你创建了多少敌人,并且在达到限制时不运行setTimeout : var initEnemies = function () { var numEnemiesCreated = 0; function createAnotherEnemy() { var randomX = Math.floor(Math.random() * 190); v ...
-
这是否意味着10秒后应用程序将恢复其“暂停”状态? 如果你仔细阅读: 一旦被唤醒,该应用程序有大约10秒钟来处理数据。 理想情况下,它应该尽可能快地处理数据并允许自己再次暂停。 但是,如果需要更多时间,应用程序可以使用beginBackgroundTaskWithExpirationHandler:方法来请求额外的时间; 但是,只有在绝对必要时才应该这样做。 应用程序通常通过后台模式唤醒(如位置服务,音频,推送通知等),对于某些模式(如位置服务),它将保持清醒,直到捕获位置数据,对于某些模式,它不会保持清醒 ...
-
这只是我对CountDownTimer的调查,当我在几个月前使用CountDownTimer时,在我的应用程序中它的工作正常。 public void onTick(long millisUntilFinished) 这millisUntilFinished将剩余时间以毫秒为单位,最后1000毫秒是调用onFinish()方法,因此onTick方法将被调用,直到剩余时间超过(1000(对于OnFinish)+ 1000(对于计数器))毫秒,如果最后剩余的毫秒小于2000毫秒,它将跳过onTick(),当定 ...
-
而不是mousedown ,你应该使用iPad的touchstart和touchend事件,详见Apple文档或Mozilla文档 。 尝试这个: $('#nw_scroll_down').bind( "touchstart", function(e){ scrolling = setInterval(function() { $('.mod_article').scrollTop( $('.mod_article').scrollTop() + 5 ); },25); } ...
-
要使这些样式同时影响Firefox和IE,您需要添加-moz-(对于Firefox)和-ms-(对于Internet Explorer)。 例如, html { -moz-background-size:cover; -ms-background-size:cover; -webkit-background-size:cover; background-size:cover; } 等等... To get those styles to affect both Firefox and IE, you'll ...