本文介绍了调用异步函数并关闭应用程序(激发并忘记)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例代码
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.
更多推荐
调用异步函数并关闭应用程序(激发并忘记)
发布评论