首页 \ 问答 \ 在WPF应用程序中运行WCF侦听器(Running a WCF listener in a WPF application)

在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
更新时间:2023-11-26 13:11

最满意答案

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);
}

更新

这是一个带有setIntervalclearInterval的版本。 您仍需要计算到目前为止已创建的敌人数量,并且必须在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 and clearInterval. You still have to count how many enemies you've created so far, and you have to use interval id in clearInterval 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 ...
  • 我认为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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。