[ACCEPTED]-Calling a C# method, and make it take 10 seconds to return-multithreading
You could create a wrapper method which 1 does the appropriate sleep.
Thread.Sleep(TimeSpan.FromSeconds(10))
Start a new thread that sleeps for 10 sec, then 2 return, that way the time that the methos 1 takes to run won't add to the 10 seconds
using System.Threading;
public static WCF(object obj)
{
Thread newThread =
new Thread(new ThreadStart(Work));
newThread.Start();
//do method here
newThread.Join();
return obj;
}
static void Work()
{
Thread.Sleep(10000);
}
If you mean without changing the code on 3 the other (Server-side) end of the WCF call, (since 2 if you can change the code there then the 1 answer is obvious),
then no..
If this is just for testing, you could have 6 the proxy class point to a web proxy that 5 simulates the timeout. Using Fiddler you could 4 script the request/response to be delayed 3 by 10 seconds and then have the proxy class 2 use Fiddler to make web service requests 1 by setting the "Proxy" property:
IWebProxy proxy = new WebProxy("http://localhost:8888", true);
webService.Proxy = proxy;
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.