简体   繁体   English

MVVMLight Messenger发送-暂停方法

[英]MVVMLight Messenger Send - Pause method

I'm converting a program to MVVM Light from Code Behind. 我正在从“隐藏代码”将程序转换为MVVM Light。

Part of this software, has to read in a CSV file from our bank, grab all the data, transform it, the copy it into a new CSV that will then get uploaded to our Accounting Software. 此软件的一部分,必须从我们的银行读取CSV文件,获取所有数据,进行转换,然后将其复制为新的CSV,然后将其上传到我们的会计软件中。

Using code behind, whilst reading the CSV, it would open up a new form if it was the first time that credit card had been uploaded, in order to set some defaults up, then once the defaults are set, it would continue processing. 如果是第一次上传信用卡,则使用后面的代码读取CSV时会打开一个新表格,以便设置一些默认值,一旦设置了默认值,它将继续处理。

I've been using the MessengerInstance to swap between forms and pass data between viewmodels. 我一直在使用MessengerInstance在表单之间交换和在视图模型之间传递数据。 But I don't know how to send the message, pause the current running method until a message is sent back. 但是我不知道如何发送消息,请暂停当前运行的方法,直到发送回消息为止。

Send Message 发信息

     selectedCreditCard =
           _creditCardList.SingleOrDefault(x => x.CreditCardNumber == existingColumns[1]);
                 if (selectedCreditCard == null)
                 {
                     MessengerInstance.Send(Messaging.FormChanged.NewCreditCard);
                     MessengerInstance.Send(existingColumns[1], Messaging.MessengerTokens.
                  }

Receive Message 接收讯息

  public NewCreditCardViewModel()
    {
        Messenger.Default.Register<string>(this, Messaging.MessengerTokens.NewCreditCards, value => AccountName = value);

        SaveCommand = new RelayCommand(SaveNewCreditCard);
        RefreshCommand = new RelayCommand(RefreshVendorsAndReviewers);
        CreditCard = new VPCreditCard();
    }

If i understand you correctly 如果我正确理解你

You want to keep this decoupled with messages, then just send a message back on OK from the defaults form to continue processing. 您希望将其与消息保持分离,然后只需从默认表单中的确定发送回一条消息即可继续进行处理。 Ie save the state and continue where you left off with the defaults 即保存状态并继续使用默认设置

  1. Process CSV part 1 (stop processing, save state, check for new cc) 处理CSV第1部分(停止处理,保存状态,检查新抄送)

    1.a - If new cc, send message to defaults form (if not new cc, Process CSV part 2 ) 1.a-如果是新抄送,则将邮件发送到默认表单(如果不是新抄送,则处理CSV第2部分)

    1.b - Defaults opens, on OK, Send message back processing form 1.b-默认设置打开,单击确定,发送回信处理表格

  2. Receive finished defaults message, Process CSV part 2 (continue where left off) 接收完成的默认消息,处理CSV第2部分(从上次中断处继续)

The premise is you just have to break CSV processing in to 2 parts, 2 methods, and allow it to resume it self via its state 前提是您只需要将CSV处理分为2部分,2种方法,并允许其通过其状态自行恢复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM