You don't need to keep your object alive. You don't need to keep the thread
alive too. It will STAY alive. With "serverObject it generates a second
thread to run in the background", do you mean that you create a background
thread (thread.IsBackground = true)? If that's the case, set it to "false",
and you'll be okay.

P.S. I've actually built a WS and tested it... here's a snippet in C#

<snippet>
//... other namespaces omitted for brevity
using System.Threading;
using System.IO;


namespace MtWs
{
        public class MTWebService : System.Web.Services.WebService
        {
                // ctor and the rest of the methods omitted...

                [WebMethod]
                public void DoSomethingAsync()
                {
                        Thread t = new Thread(new ThreadStart(AsyncThreadProc));
                        t.IsBackground = false;
                        t.Start();
                }

                private void AsyncThreadProc()
                {
                        Thread.Sleep(10000);
                        StreamWriter w = new 
StreamWriter(Server.MapPath("./Test.txt"), true);
                        w.WriteLine("Hello from {0}", 
Thread.CurrentThread.GetHashCode());
                        w.Close();
                }
        }
}
</snippet>

Don't forget to give IUSR_XXX write permissions on the web folder, if you
run the sample...

Cheers,
Stoyan Damov

-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] Behalf Of Ned
Sent: 08/18/2003 11:12
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Web services & server side multithreading.


I am currently working on developing a web service that must use
multithreading to achieve the required functionality. Because web services
are stateless I'm having a lot of difficulty keeping the auxillary thread
alive on the server. When the client connects to the server a new object,
serverObject, is created and saved as a session variable. During the
creation of the serverObject it generates a second thread to run in the
background. As soon as the initial connection between the client and server
is completed the auxilary thread dies.

I had hoped that by saving the parent object as a session variable all
child objects, including threads, would stay alive. I'm finding that all of
the other child variables and objects, including event callbacks, are
maintained so this is specific to threading.

Does anyone have any suggestions on how I can keep this thread alive?

Thanks,
Ned.
KUKA Roboter GmbH.

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to