T
Trecius
Hello, Newsgroupians:
I've two questions regarding the System.Threading.Thread namespace.
First, what is the point of having a ThreadStart parameter? For example...
using System.Threading;
Thread myThread;
myThread = new Thread(new ThreadStart(myFunc)); // This works
myThread = new Thread(myFunc); // And this works
Why not just make it easy and always use the second calling?
My second question is slightly more detailed.
I have a thread that I have created in a class...
using System.Threading;
public struct MyPoint
{
public float x;
public float y;
}
Thread m_myThread;
MyPoint m_pt;
class MyClass
{
void ThreadStartFunc()
{
m_pt.x = 1;
m_pt.y = 2;
m_myThread = new Thread(this.SomeThreadFunc);
}
void SomeThreadFunc()
{
m_pt.x = 5;
m_pt.y = 6;
}
}
Now suppose I call ThreadStartFunc(); in it, I initialize x and y. When I
debug, I notice the value of x and y are INITIALLY 1 and 2 in the
SomeThreadFunc(). Later in the thread I change the values, and the thread
terminates. However, when looking at the values in the main thread, I notice
that the values are still 1 and 2. Can someone explain why this is
happening? Thank you for your assistance.
Trecius
I've two questions regarding the System.Threading.Thread namespace.
First, what is the point of having a ThreadStart parameter? For example...
using System.Threading;
Thread myThread;
myThread = new Thread(new ThreadStart(myFunc)); // This works
myThread = new Thread(myFunc); // And this works
Why not just make it easy and always use the second calling?
My second question is slightly more detailed.
I have a thread that I have created in a class...
using System.Threading;
public struct MyPoint
{
public float x;
public float y;
}
Thread m_myThread;
MyPoint m_pt;
class MyClass
{
void ThreadStartFunc()
{
m_pt.x = 1;
m_pt.y = 2;
m_myThread = new Thread(this.SomeThreadFunc);
}
void SomeThreadFunc()
{
m_pt.x = 5;
m_pt.y = 6;
}
}
Now suppose I call ThreadStartFunc(); in it, I initialize x and y. When I
debug, I notice the value of x and y are INITIALLY 1 and 2 in the
SomeThreadFunc(). Later in the thread I change the values, and the thread
terminates. However, when looking at the values in the main thread, I notice
that the values are still 1 and 2. Can someone explain why this is
happening? Thank you for your assistance.
Trecius