-
July 19th, 2007, 06:51 AM
#1
Multithreaded consumer
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.
Also, I can't step into the web service code from the new thread, but I can from the normal thread...
Here's the consumer code:
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,
Toot
Some cause happiness wherever they go; others, whenever they go.
-
July 19th, 2007, 07:04 AM
#2
Re: Multithreaded consumer
For the normal function, you use m_WS. For the thread, you create a new webservice. Are you missing some initializing functions?
Check if that line even succeeds (creating the service in the thread), maybe that line is failing.
-
July 19th, 2007, 07:19 AM
#3
Re: Multithreaded consumer
Originally Posted by Tischnoetentoet
For the normal function, you use m_WS. For the thread, you create a new webservice. Are you missing some initializing functions?
Check if that line even succeeds (creating the service in the thread), maybe that line is failing.
Nothing missing and after the new, there is definitely an object. Also tried using the member but no difference. It really does seem to be the fact that it's on a different thread; almost as if the proxy (or debugger???) is only allowing it to run on the GUI thread, for whatever reason...???
Some cause happiness wherever they go; others, whenever they go.
-
July 19th, 2007, 07:27 AM
#4
Re: Multithreaded consumer
I think I see what's wrong. The thread goes out of scope, so it is closed.
Maybe I am thinking wrong, but try making the thread object a class object instead of a function object.
-
July 19th, 2007, 08:28 AM
#5
Re: Multithreaded consumer
Originally Posted by Tischnoetentoet
I think I see what's wrong. The thread goes out of scope, so it is closed.
Maybe I am thinking wrong, but try making the thread object a class object instead of a function object.
Tried that: no difference.... keep the ideas rolling!
Cheers,
T
Some cause happiness wherever they go; others, whenever they go.
-
July 19th, 2007, 08:31 AM
#6
Re: Multithreaded consumer
But the thread just quits?
-
July 19th, 2007, 09:08 AM
#7
Re: Multithreaded consumer
Yup - there's a bit of a debugger hang where nothing seems to happen for a while, then the thread's gone & I see a "The thread 0xnnnn has exited with code 0 (0x0)." in the output window (I know it's the same thread because I've put a "thread 0xnnnn starting" message at the top of the thread proc).
Some cause happiness wherever they go; others, whenever they go.
-
July 19th, 2007, 09:10 AM
#8
Re: Multithreaded consumer
Just for your information: you can give threads ID's so you can recognize them
You stepped through the thread code using F10 (Step)? Which line in the ThreadProc makes the thread close?
-
July 20th, 2007, 05:23 AM
#9
Re: Multithreaded consumer
What attribute of Thread is that??? I know you can give them names, didn't realise you could assign an ID too.
Anyhow, stepping over or into any WebMethod on my WebService blows the thread. So in the code above, the first line in the try block in the ThreadProc method:
Code:
NetQCws.DynamicHostInfo[] infos = svc.GetDynamicHostInfo();
Cheers,
T
Some cause happiness wherever they go; others, whenever they go.
-
July 20th, 2007, 05:39 AM
#10
Re: Multithreaded consumer
And if you don't call the first function (outside the thread), does it still quit?
And about the thread ID, I was talking about the name property :S, my fault!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|