不想等待方法返回 [英] Don't want to wait for method to return

查看:48
本文介绍了不想等待方法返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉"C#不要等待对象的方法返回?

Is there a way to "tell" C# not to wait for object's method to return?

使用 COM (VbScript) 我可以在不等待返回的情况下触发一个方法,所以我想以同样的方式使用 C#.

Using COM (VbScript) I'm able to fire a method without waiting for it to return, so I would like to use C# the same way.

VbScript 代码:

The VbScript Code:

Dim qtApp
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Open("C:\Temp\Test")

qtApp.Run   '// VbScript does not wait for this method to finish

Set qtApp = Nothing

C# 代码:

//Refer the object
var qtApp = new QuickTest.Application();
//Open the test
qtApp.Open("C:\\Temp\\Test");

qtApp.Test.Run(); //<<== @ this step my code is waiting for the Run method to return
qtApp.Test.Pause(); //<<== This line is never executed until Run returns

评论:

  1. 引用的对象 (QuickTestApplication) 是 COM 对象,具有运行和暂停的方法(如上面的代码中所述).
  2. 对我来说 QuickTestApplication 是一个黑匣子
  3. 我不想使用 ThreadASync(基本上是线程),但是 QuickTestApplication 内置方法
  1. The object referred (QuickTestApplication) is COM object has methods for Run and Pause ( as mentioned in the code above).
  2. For me QuickTestApplication is a black box
  3. I do not want to use Thread or ASync (which is basically threading), but the QuickTestApplicationbuild in methods

如果可以使用 C# 来完成,我真的在寻找简单的答案

I really look for simple answer if it can be done using C#

推荐答案

QTP 自动化允许异步运行测试,查看文档:

The QTP automation allows running a test asynchronously, look at the documentation:

因此,您必须提供默认结果选项,而不是运行普通的 Run(在 Test 属性上,而不是像您在示例中所做的那样运行 QTP 应用程序)为 WaitOnReturn

So instead of running plain Run (on the Test Property not the QTP application as you did in your sample) you have to provide a default result-options and then specify False for WaitOnReturn

Set resOpt = CreateObject("QuickTest.RunResultsOptions")
qtApp.Test.Run resOpt, False

这篇关于不想等待方法返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆