Can not create new thread in web method?

Can not create new thread in web method?

Post by aGg » Sun, 13 May 2007 13:17:00


Hi , all
I must call a web mothod synchronouslyn this web method , I need do
something asynchronouslyy code is below, the BackgroundWorker seemed not
to be able to work in web service project .

public class Service1 : System.Web.Services.WebService
{

[WebMethod]
public string test()
{
BackgroundWorker oWork = new BackgroundWorker();
oWork.DoWork += new DoWorkEventHandler(a);
oWork.RunWorkerAsync();
return "test return";
}

private void a(object sender, DoWorkEventArgs e)
{
System.Threading.Thread.Sleep(10000);

}

// end . thanks
 
 
 

Can not create new thread in web method?

Post by John Saund » Tue, 15 May 2007 01:09:36


Isn't the BackgroundWorker component for Windows Forms applications? That
would suggest it is dependent on a message pump, which does not exist
outside of a UI application.

You'll have to do it the old fashioned way.
--
John Saunders [MVP]