views:

771

answers:

4

From a web service (WCF), I want an endpoint to take 10 seconds to finish.

Is there a way I can do a thread.sleep(10); on the method?

+9  A: 

You could create a wrapper method which does the appropriate sleep.

Thread.Sleep(TimeSpan.FromSeconds(10))
JaredPar
seconds, not minutes
Dmitri Nesteruk
@nesteruk, thanks. I updated the answer
JaredPar
System.Threading.Thread.Sleep(10000)
Michael Haren
A: 

If you mean without changing the code on the other (Server-side) end of the WCF call, (since if you can change the code there then the answer is obvious),

then no..

Charles Bretana
+2  A: 

Start a new thread that sleeps for 10 sec, then return, that way the time that the methos 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);
    }
rizzle
A: 

If this is just for testing, you could have the proxy class point to a web proxy that simulates the timeout. Using Fiddler you could script the request/response to be delayed by 10 seconds and then have the proxy class use Fiddler to make web service requests by setting the "Proxy" property:

IWebProxy proxy = new WebProxy("http://localhost:8888", true);
webService.Proxy = proxy;
Tautologistics