调用异步函数并关闭应用程序(激发并忘记)

编程入门 行业动态 更新时间:2024-10-07 00:18:34
本文介绍了调用异步函数并关闭应用程序(激发并忘记)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

示例代码

Sample code

static void Main(string[] args) { ServiceReference1.BankCardSoapClient s = new ServiceReference1.BankCardSoapClient(); Task[] tasks = new Task[]{ Task.Factory.StartNew(() => s.test(), TaskCreationOptions.LongRunning), Task.Factory.StartNew(() => s.test2(), TaskCreationOptions.LongRunning) }; Task.WaitAll(tasks, System.Threading.Timeout.Infinite); //Thread.Sleep(277); }

如果没有sleep方法,代码不会触发,它也会抛出超时异常。 当我调用异步版本的test和test2工作正常,但需要睡眠时间更长的睡眠功能。 如果没有失败并且没有使用睡眠功能,我该怎么做才能触发Web服务功能?

The code does not trigger without the sleep method and it also throws timeout exception. When I called the async versions of test and test2 works fine, but needs to have sleep function with higher sleeping time. What should I do to trigger the web service function without fail and without using sleep function?

推荐答案

你正在尝试什么过程打电话?它是一个外部过程,如记事本或可执行文件?如果没有,我认为你不能做你想做的事。一旦你关闭应用程序就没有什么可以实际*做*这个过程,所以你必须等到它完成才关闭。 如果你只是尝试启动外部程序,使用Process。以下是一些示例: //启动Internet Explorer System.Diagnostics.Process.Start(IExplore.exe); //打开一个目录 System.Diagnostics.Process.Start(c:\ temp); 启动流程后,您可以关闭申请。 What is the process that you are trying to call? Is it an external process, like Notepad or an executable? If not, I don't think you can do what you want to do. Once you close the app there is nothing to actually *do* the process any more, so you have to wait until it is finished before closing. If you are just trying to launch an external program, use "Process". Here are some examples: // start up internet explorer System.Diagnostics.Process.Start("IExplore.exe"); // open up a directory System.Diagnostics.Process.Start("c:\temp"); Once you have launched the process you can close the application.

更多推荐

调用异步函数并关闭应用程序(激发并忘记)

本文发布于:2023-11-28 06:16:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641259.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   函数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!