Click here to Skip to main content
15,883,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sample code

C#
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);

}



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?
Posted
Updated 30-May-14 3:25am
v2
Comments
Prasad Khandekar 16-May-14 5:40am    
Try changing your code to

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

Ragards,
ckumaresanmba 16-May-14 5:57am    
Prasad Khandekar: Thanks for your comment.
It throws timeout exceptions when the call exceeds time limit. I know I can increase timeout, But I just want to trigger calls, no need for the return results.
agent_kruger 16-May-14 10:29am    
sir, i am unable to find a question inside that piece of a paragraph?
Francine DeGrood Taylor 2-Jun-14 14:00pm    
Let me see if I understand what you are wanting. You want the asynch processes to start and you don't want to wait for them to finish. You want them to just run independently and then the application will move on and not be concerned with the processes any more. Is this correct?
ckumaresanmba 3-Jun-14 1:50am    
Correct. Also the calling application will be ended after calling the async process. The calling application has only task that is to call the async process.

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900