Multithreaded consumer

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi. I have a C# WebService with a WebMethod that returns an array of
(WebService-defined) objects. If I create a consumer exe and call the
method, everything is as expected.
If I then create a thread within my exe and call the WebMethod from
there, my thread dies. No exception, it just dies. At one point I
had a few unhandled socket exceptions mentioned in the Debug window,
but something's changed and they're not appearing now.
Here's the consumer code:

private void GetInfoButton_Click(object sender, EventArgs e)
{
if (CreateReference())
{
NetQCws.DynamicHostInfo[] infos =
m_WS.GetDynamicHostInfo();

foreach (NetQCws.DynamicHostInfo inf in infos)
Debug.WriteLine(string.Format("ST: {0}@{1} last
seen {2}", inf.Hostname, inf.IP_Address, inf.LastSeen.ToString("T")));
}

// and now threaded
System.Threading.Thread thr = new
System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
thr.Name = "info worker thread";
thr.Start();
}

private void ThreadProc()
{
NetQCws.Service svc = new NetQCClient.NetQCws.Service();

try
{
NetQCws.DynamicHostInfo[] infos =
svc.GetDynamicHostInfo();
foreach (NetQCws.DynamicHostInfo inf in infos)
{
Debug.WriteLine("blah");
}
}
catch (Exception ex)
{
Debug.WriteLine(string.Format("ERROR: {0}",
ex.Message));
}

}

Any clues?

Thanks for your time,
Andy C

.


Quantcast